Skip to content

Commit

Permalink
chore(webpack): Switch to TerserPlugin. Split bundles into ~5mb chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherthielen committed Feb 7, 2019
1 parent 1586e0a commit a35088a
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 36 deletions.
12 changes: 9 additions & 3 deletions app/scripts/modules/amazon/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const basePath = path.join(__dirname, '..', '..', '..', '..');
const NODE_MODULE_PATH = path.join(basePath, 'node_modules');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const exclusionPattern = /(node_modules|\.\.\/deck)/;
const WEBPACK_THREADS = Math.max(require('physical-cpu-count') - 1, 1);

Expand All @@ -32,11 +32,17 @@ module.exports = {
optimization: {
minimizer: IS_PRODUCTION
? [
new UglifyJSPlugin({
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: true,
uglifyOptions: { mangle: false },
terserOptions: {
ecma: 6,
mangle: false,
output: {
comments: false,
},
},
}),
]
: [], // disable minification in development mode
Expand Down
12 changes: 9 additions & 3 deletions app/scripts/modules/appengine/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const basePath = path.join(__dirname, '..', '..', '..', '..');
const NODE_MODULE_PATH = path.join(basePath, 'node_modules');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const exclusionPattern = /(node_modules|\.\.\/deck)/;
const WEBPACK_THREADS = Math.max(require('physical-cpu-count') - 1, 1);

Expand All @@ -32,11 +32,17 @@ module.exports = {
optimization: {
minimizer: IS_PRODUCTION
? [
new UglifyJSPlugin({
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: true,
uglifyOptions: { mangle: false },
terserOptions: {
ecma: 6,
mangle: false,
output: {
comments: false,
},
},
}),
]
: [], // disable minification in development mode
Expand Down
12 changes: 9 additions & 3 deletions app/scripts/modules/cloudfoundry/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const basePath = path.join(__dirname, '..', '..', '..', '..');
const NODE_MODULE_PATH = path.join(basePath, 'node_modules');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const exclusionPattern = /(node_modules|\.\.\/deck)/;
const WEBPACK_THREADS = Math.max(require('physical-cpu-count') - 1, 1);

Expand All @@ -32,11 +32,17 @@ module.exports = {
optimization: {
minimizer: IS_PRODUCTION
? [
new UglifyJSPlugin({
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: true,
uglifyOptions: { mangle: false },
terserOptions: {
ecma: 6,
mangle: false,
output: {
comments: false,
},
},
}),
]
: [], // disable minification in development mode
Expand Down
12 changes: 9 additions & 3 deletions app/scripts/modules/core/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const basePath = path.join(__dirname, '..', '..', '..', '..');
const NODE_MODULE_PATH = path.join(basePath, 'node_modules');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const exclusionPattern = /(node_modules|\.\.\/deck)/;
const WEBPACK_THREADS = Math.max(require('physical-cpu-count') - 1, 1);

Expand All @@ -32,11 +32,17 @@ module.exports = {
optimization: {
minimizer: IS_PRODUCTION
? [
new UglifyJSPlugin({
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: true,
uglifyOptions: { mangle: false },
terserOptions: {
ecma: 6,
mangle: false,
output: {
comments: false,
},
},
}),
]
: [], // disable minification in development mode
Expand Down
12 changes: 9 additions & 3 deletions app/scripts/modules/docker/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const basePath = path.join(__dirname, '..', '..', '..', '..');
const NODE_MODULE_PATH = path.join(basePath, 'node_modules');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const exclusionPattern = /(node_modules|\.\.\/deck)/;
const WEBPACK_THREADS = Math.max(require('physical-cpu-count') - 1, 1);

Expand All @@ -32,11 +32,17 @@ module.exports = {
optimization: {
minimizer: IS_PRODUCTION
? [
new UglifyJSPlugin({
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: true,
uglifyOptions: { mangle: false },
terserOptions: {
ecma: 6,
mangle: false,
output: {
comments: false,
},
},
}),
]
: [], // disable minification in development mode
Expand Down
12 changes: 9 additions & 3 deletions app/scripts/modules/ecs/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const basePath = path.join(__dirname, '..', '..', '..', '..');
const NODE_MODULE_PATH = path.join(basePath, 'node_modules');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const exclusionPattern = /(node_modules|\.\.\/deck)/;
const WEBPACK_THREADS = Math.max(require('physical-cpu-count') - 1, 1);

Expand All @@ -32,11 +32,17 @@ module.exports = {
optimization: {
minimizer: IS_PRODUCTION
? [
new UglifyJSPlugin({
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: true,
uglifyOptions: { mangle: false },
terserOptions: {
ecma: 6,
mangle: false,
output: {
comments: false,
},
},
}),
]
: [], // disable minification in development mode
Expand Down
12 changes: 9 additions & 3 deletions app/scripts/modules/google/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const basePath = path.join(__dirname, '..', '..', '..', '..');
const NODE_MODULE_PATH = path.join(basePath, 'node_modules');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const exclusionPattern = /(node_modules|\.\.\/deck)/;
const WEBPACK_THREADS = Math.max(require('physical-cpu-count') - 1, 1);

Expand All @@ -32,11 +32,17 @@ module.exports = {
optimization: {
minimizer: IS_PRODUCTION
? [
new UglifyJSPlugin({
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: true,
uglifyOptions: { mangle: false },
terserOptions: {
ecma: 6,
mangle: false,
output: {
comments: false,
},
},
}),
]
: [], // disable minification in development mode
Expand Down
12 changes: 9 additions & 3 deletions app/scripts/modules/kubernetes/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const basePath = path.join(__dirname, '..', '..', '..', '..');
const NODE_MODULE_PATH = path.join(basePath, 'node_modules');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const exclusionPattern = /(node_modules|\.\.\/deck)/;
const WEBPACK_THREADS = Math.max(require('physical-cpu-count') - 1, 1);

Expand All @@ -32,11 +32,17 @@ module.exports = {
optimization: {
minimizer: IS_PRODUCTION
? [
new UglifyJSPlugin({
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: true,
uglifyOptions: { mangle: false },
terserOptions: {
ecma: 6,
mangle: false,
output: {
comments: false,
},
},
}),
]
: [], // disable minification in development mode
Expand Down
12 changes: 9 additions & 3 deletions app/scripts/modules/openstack/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const basePath = path.join(__dirname, '..', '..', '..', '..');
const NODE_MODULE_PATH = path.join(basePath, 'node_modules');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const exclusionPattern = /(node_modules|\.\.\/deck)/;
const WEBPACK_THREADS = Math.max(require('physical-cpu-count') - 1, 1);

Expand All @@ -32,11 +32,17 @@ module.exports = {
optimization: {
minimizer: IS_PRODUCTION
? [
new UglifyJSPlugin({
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: true,
uglifyOptions: { mangle: false },
terserOptions: {
ecma: 6,
mangle: false,
output: {
comments: false,
},
},
}),
]
: [], // disable minification in development mode
Expand Down
12 changes: 9 additions & 3 deletions app/scripts/modules/titus/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const basePath = path.join(__dirname, '..', '..', '..', '..');
const NODE_MODULE_PATH = path.join(basePath, 'node_modules');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const exclusionPattern = /(node_modules|\.\.\/deck)/;
const WEBPACK_THREADS = Math.max(require('physical-cpu-count') - 1, 1);

Expand All @@ -32,11 +32,17 @@ module.exports = {
optimization: {
minimizer: IS_PRODUCTION
? [
new UglifyJSPlugin({
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: true,
uglifyOptions: { mangle: false },
terserOptions: {
ecma: 6,
mangle: false,
output: {
comments: false,
},
},
}),
]
: [], // disable minification in development mode
Expand Down
29 changes: 23 additions & 6 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const md5 = require('md5');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');

const CACHE_INVALIDATE = getCacheInvalidateString();
const NODE_MODULE_PATH = path.join(__dirname, 'node_modules');
Expand Down Expand Up @@ -34,15 +34,32 @@ function configure(env, webpackOpts) {
},
devtool: IS_PRODUCTION ? 'source-map' : 'eval',
optimization: {
splitChunks: { chunks: 'all' },
splitChunks: {
chunks: 'all', // enables splitting of both initial and async chunks
maxInitialRequests: 20, // allows up to 10 initial chunks
cacheGroups: {
// Put code matching each regexp in a separate chunk
core: new RegExp('/app/scripts/modules/core/'),
providers: new RegExp('/app/scripts/modules/(?!core)[^/]+/'),
vendor_A_F: new RegExp('node_modules/[a-fA-F]'),
vendor_G_O: new RegExp('node_modules/[g-oG-O]'),
vendor_P_Q: new RegExp('node_modules/[^a-oA-Or-zR-Z]'),
vendor_R_Z: new RegExp('node_modules/[r-zR-Z]'),
},
},
minimizer: IS_PRODUCTION
? [
new UglifyJSPlugin({
parallel: true,
new TerserPlugin({
cache: true,
test: /vendors/,
parallel: true,
sourceMap: true,
uglifyOptions: { mangle: false },
terserOptions: {
ecma: 6,
mangle: false,
output: {
comments: false,
},
},
}),
]
: [], // Disable minification unless production
Expand Down

0 comments on commit a35088a

Please sign in to comment.