-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.prod.js
85 lines (75 loc) · 1.98 KB
/
webpack.prod.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const { resolve } = require('path');
const webpack = require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const commonConfig = require('./webpack.common');
const config = {
mode: 'production',
devtool: 'cheap-module-source-map',
entry: [
'./app.jsx',
],
output: {
filename: 'js/[name].bundle.js',
path: resolve(__dirname, 'dist'),
publicPath: '/',
},
optimization: {
nodeEnv: 'production',
sideEffects: false, // changed to false for material-web-components
concatenateModules: true,
occurrenceOrder: true,
// runtimeChunk: true,
minimize: true,
minimizer: [
new OptimizeCSSAssetsPlugin({}),
new TerserPlugin({
parallel: true,
cache: true,
sourceMap: true,
terserOptions: {
warnings: false,
compress: {
comparisons: false,
},
parse: {},
mangle: true,
output: {
comments: false,
ascii_only: true,
},
},
}),
],
},
};
const prodPlugins = [
new CleanWebpackPlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false,
}),
new webpack.DefinePlugin({ 'process.env': { NODE_ENV: JSON.stringify('production') } }),
new MiniCssExtractPlugin({
filename: 'styles/[name].bundle.css',
}),
new CompressionPlugin({
algorithm: 'gzip',
test: /\.(js|css|html|svg)$/,
threshold: 10240,
compressionOptions: { level: 6 },
minRatio: 0.8,
}),
];
const prodConfig = {
...commonConfig,
...config,
};
prodPlugins.forEach((eachPlugin) => {
prodConfig.plugins.push(eachPlugin);
});
module.exports = prodConfig;