Skip to content

Commit

Permalink
chore: optimize build
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Werner committed Jan 27, 2018
1 parent a3b229f commit aa92efd
Show file tree
Hide file tree
Showing 4 changed files with 652 additions and 7 deletions.
4 changes: 3 additions & 1 deletion config/webpack.base.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const path = require('path');
const webpack = require('webpack');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
const isProd = process.env.NODE_ENV === 'production';

const baseConfig = {
Expand All @@ -22,7 +23,8 @@ const baseConfig = {
PRODUCTION: isProd,
DEVELOPMENT: !isProd,
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
})
}),
new HardSourceWebpackPlugin(),
],
module: {
rules: [
Expand Down
45 changes: 39 additions & 6 deletions config/webpack.client.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,68 @@ const clientConfig = merge(baseConfig, {
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: (module) => module.context && module.context.indexOf('node_modules') !== -1
minChunks: (module) => {
return module.context && module.context.includes('node_modules');
}
}),
new webpack.optimize.CommonsChunkPlugin('manifest'),
new HTMLPlugin({
template: 'src/app/index.template.html'
}),
})
]
});

if (process.env.NODE_ENV === 'production') {
clientConfig.plugins = (clientConfig.plugins || []).concat([
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
parallel: 4,
uglifyOptions: {
compress: {
arrows: false,
booleans: false,
cascade: false,
collapse_vars: false,
comparisons: false,
computed_props: false,
hoist_funs: false,
hoist_props: false,
hoist_vars: false,
if_return: false,
inline: false,
join_vars: false,
keep_infinity: true,
loops: false,
negate_iife: false,
properties: false,
reduce_funcs: false,
reduce_vars: false,
sequences: false,
side_effects: false,
switches: false,
top_retain: false,
toplevel: false,
typeofs: false,
unused: false,
conditionals: true,
dead_code: true,
evaluate: true
},
mangle: true
}
}),
new webpack.LoaderOptionsPlugin({
minimize: true
}),
new ServiceWorkerWebpackPlugin({
entry: path.join(__dirname, '..', 'src/client/sw.ts'),
entry: path.join(__dirname, '..', 'src/client/sw.ts')
}),
new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$/,
threshold: 0,
minRatio: 1
}),
})
]);
}

Expand Down
Loading

0 comments on commit aa92efd

Please sign in to comment.