Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): Upgrade to Webpack 4 #944

Merged
merged 2 commits into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"presets": [
["es2015", { "modules": false }],
"es2015",
"es2016",
"react"
],
Expand Down
203 changes: 85 additions & 118 deletions build/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,122 +9,89 @@ const MODEL3D_STATIC_ASSETS_VERSION = '1.12.0';
const SWF_STATIC_ASSETS_VERSION = '0.112.0';
const TEXT_STATIC_ASSETS_VERSION = '0.114.0';

const getTestFile = (src) => {
if (!src) {
return [
'src/lib/**/*-test.js',
'src/lib/**/*-test.html'
];
}

if (src.endsWith('/')) {
return [
`src/lib/${src}**/*-test.js`,
`src/lib/${src}**/*-test.html`
];
}

const frags = src.split('/');
const fileName = frags[frags.length - 1];
if (!fileName) {
throw new Error('Incorrect path to source file');
}

const path = src.replace(fileName, '');
const base = path ? `src/lib/${path}` : 'src/lib';
return [
`${base}/__tests__/${fileName}-test.js`,
`${base}/__tests__/${fileName}-test.html`
];
};

module.exports = (config) => config.set({
autoWatch: false,

basePath: '..',

browserConsoleLogOptions: {
level: 'log',
format: '%b %T: %m',
terminal: true
},

browsers: ['PhantomJS'],

browserNoActivityTimeout: 100000,

captureConsole: true,

colors: true,

coverageReporter: {
check: config.src ? {} : {
global: {
statements: 80,
branches: 80,
functions: 80,
lines: 80
}
module.exports = config =>
config.set({
autoWatch: false,

basePath: '..',

browserConsoleLogOptions: {
level: 'log',
format: '%b %T: %m',
terminal: true,
},

browsers: ['PhantomJS'],

browserNoActivityTimeout: 100000,

captureConsole: true,

colors: true,

coverageReporter: {
check: config.src
? {}
: {
global: {
statements: 80,
branches: 80,
functions: 80,
lines: 80,
},
},
reporters: [
{
type: 'html',
dir: 'reports/coverage/html',
},
{
type: 'cobertura',
dir: 'reports/coverage/cobertura',
},
{ type: 'text' },
],
},

junitReporter: {
outputDir: 'reports/coverage/junit',
outputFile: 'junit.xml',
},

frameworks: ['mocha', 'chai-dom', 'chai', 'sinon', 'sinon-chai', 'fixture'],

files: [
'https://cdn01.boxcdn.net/polyfills/core-js/2.5.3/core.min.js',
`src/third-party/model3d/${MODEL3D_STATIC_ASSETS_VERSION}/three.min.js`,
`src/third-party/doc/${DOC_STATIC_ASSETS_VERSION}/**/*.js`,
`src/third-party/media/${MEDIA_STATIC_ASSETS_VERSION}/**/*.js`,
`src/third-party/model3d/${MODEL3D_STATIC_ASSETS_VERSION}/**/*.js`,
`src/third-party/swf/${SWF_STATIC_ASSETS_VERSION}/**/*.js`,
`src/third-party/text/${TEXT_STATIC_ASSETS_VERSION}/**/*.js`,
'src/**/__tests__/**/*-test.js',
'src/**/__tests__/**/*-test.html',
],

preprocessors: {
'src/**/__tests__/**/*-test.js': ['webpack', 'sourcemap'],
'src/**/__tests__/**/*-test.html': ['html2js'],
},

phantomjsLauncher: {
exitOnResourceError: false,
},

port: 9876,

reporters: ['mocha', 'coverage', 'junit'],

logLevel: config.LOG_ERROR,

singleRun: true,

webpack: webpackConfig,

webpackMiddleware: {
noInfo: true,
},
reporters: [
{
type: 'html',
dir: 'reports/coverage/html'
},
{
type: 'cobertura',
dir: 'reports/coverage/cobertura'
},
{ type: 'text' }
]
},

junitReporter: {
outputDir: 'reports/coverage/junit',
outputFile: 'junit.xml'
},

frameworks: [
'mocha',
'chai-dom',
'chai',
'sinon',
'sinon-chai',
'fixture'
],

files: [
'https://cdn01.boxcdn.net/polyfills/core-js/2.5.3/core.min.js',
`src/third-party/model3d/${MODEL3D_STATIC_ASSETS_VERSION}/three.min.js`,
`src/third-party/doc/${DOC_STATIC_ASSETS_VERSION}/**/*.js`,
`src/third-party/media/${MEDIA_STATIC_ASSETS_VERSION}/**/*.js`,
`src/third-party/model3d/${MODEL3D_STATIC_ASSETS_VERSION}/**/*.js`,
`src/third-party/swf/${SWF_STATIC_ASSETS_VERSION}/**/*.js`,
`src/third-party/text/${TEXT_STATIC_ASSETS_VERSION}/**/*.js`
].concat(getTestFile(config.src)),

exclude: [],

preprocessors: {
'src/lib/**/*-test.js': ['webpack', 'sourcemap'],
'src/lib/**/*-test.html': ['html2js']
},

phantomjsLauncher: {
exitOnResourceError: false
},

port: 9876,

reporters: ['mocha', 'coverage', 'junit'],

logLevel: config.LOG_ERROR,

singleRun: true,

webpack: webpackConfig,

webpackMiddleware: {
noInfo: true
}
});
});
2 changes: 1 addition & 1 deletion build/license.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = `Box Content Preview

Copyright 2017 Box, Inc. All rights reserved.
Copyright 2019 Box, Inc. All rights reserved.

This product includes software developed by Box, Inc. ("Box")
(http://www.box.com)
Expand Down
90 changes: 27 additions & 63 deletions build/webpack.common.config.js
Original file line number Diff line number Diff line change
@@ -1,104 +1,68 @@
const path = require('path');
const pkg = require('../package.json');
const webpack = require('webpack');
const I18nPlugin = require('i18n-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

const { DefinePlugin } = webpack;
const NormalPlugin = webpack.NormalModuleReplacementPlugin;
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { BannerPlugin, DefinePlugin, NormalModuleReplacementPlugin } = require('webpack');
const license = require('./license');
const pkg = require('../package.json');

/* eslint-disable global-require */
/* eslint-disable import/no-dynamic-require */
module.exports = (language) => {
module.exports = language => {
const langJson = require(`${path.resolve('src/i18n/json')}/${language}.json`);
return {
bail: true,
resolve: {
modules: ['src', 'node_modules']
},
resolveLoader: {
modules: [path.resolve('src'), path.resolve('node_modules')]
},
module: {
rules: [
{
test: /\.js$/,
use: 'babel-loader',
exclude: [
path.resolve('src/third-party'),
path.resolve('node_modules')
]
loader: 'babel-loader',
include: [path.resolve('src/lib')],
},
{
test: /\.s?css$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
importLoaders: 1
}
},
{
loader: 'postcss-loader'
},
{
loader: 'sass-loader'
}
]
}),
exclude: [
path.resolve('src/third-party'),
path.resolve('^(?!node_modules/box-annotations).*')
]
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader'],
include: [path.resolve('src/lib'), path.resolve('node_modules/box-annotations')],
},
{
test: /\.(svg|html)$/,
loader: 'raw-loader',
exclude: [
path.resolve('src/third-party'),
path.resolve('node_modules')
]
include: [path.resolve('src/lib')],
},
{
test: /\.(jpe?g|png|gif|woff2|woff)$/,
loader: 'file-loader',
include: [path.resolve('src/lib')],
options: {
name: '[name].[ext]'
name: '[name].[ext]',
},
exclude: [
path.resolve('src/third-party'),
path.resolve('node_modules')
]
}
]
},
],
},
plugins: [
new ExtractTextPlugin({
filename: '[name].css',
allChunks: true
}),
new I18nPlugin(langJson),
new BannerPlugin(license),
new DefinePlugin({
__NAME__: JSON.stringify(pkg.name),
__VERSION__: JSON.stringify(pkg.version),
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
BABEL_ENV: JSON.stringify(process.env.BABEL_ENV)
}
BABEL_ENV: JSON.stringify(process.env.BABEL_ENV),
},
}),
new NormalPlugin(/\/iconv-loader$/, 'node-noop')
new I18nPlugin(langJson),
new MiniCssExtractPlugin({
filename: '[name].css',
}),
new NormalModuleReplacementPlugin(/\/iconv-loader$/),
],
stats: {
assets: true,
children: false,
chunkModules: false,
chunks: false,
colors: true,
version: false,
hash: false,
timings: true,
chunks: false,
chunkModules: false,
children: false
}
version: false,
},
};
};
Loading