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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
"use strict";
// Important modules this config uses
var path = require('path');
var webpack = require('webpack');
var TerserPlugin = require('terser-webpack-plugin');
var CompressionPlugin = require('compression-webpack-plugin');
module.exports = require('./webpack.base.babel')({
mode: 'production',
// In production, we skip all hot-reloading stuff
entry: [require.resolve('react-app-polyfill/ie11'), path.join(process.cwd(), 'src/app.js')],
// Utilize long-term caching by adding content hashes (not compilation hashes) to compiled assets
// output: {
// filename: '[name].[chunkhash].js',
// chunkFilename: '[name].[chunkhash].chunk.js',
// },
optimization: {
minimize: true,
minimizer: [new TerserPlugin({
terserOptions: {
warnings: false,
compress: {
comparisons: false
},
drop_debugger: true,
drop_console: true,
pure_funcs: ['console.log'],
parse: {},
mangle: true,
output: {
comments: false,
ascii_only: true
}
},
parallel: true,
cache: true,
sourceMap: true
})],
nodeEnv: 'production',
chunkIds: 'deterministic',
moduleIds: 'deterministic',
usedExports: true,
sideEffects: true,
concatenateModules: true,
runtimeChunk: 'single',
splitChunks: {
maxSize: 1000 * 1024,
// 控制包的最大字节数
minSize: 10 * 1024,
// 控制包的最小字节数
cacheGroups: {
vendor: {
chunks: 'all',
minSize: 0,
maxInitialRequests: 10,
test: /[\\/]node_modules[\\/]/,
name: function name(module) {
var packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
return "npm.".concat(packageName.replace('@', ''));
}
},
bizComponent: {
chunks: 'all',
minSize: 0,
maxInitialRequests: 10,
test: /[\\/]src[\\/]components[\\/]/,
name: 'biz-component'
},
react: {
chunks: 'all',
minSize: 0,
maxInitialRequests: 10,
test: /[\\/]node_modules[\\/]react-dom[\\/]/,
name: 'react-dom'
}
}
}
},
plugins: [new CompressionPlugin({
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8
}) // new webpack.ids.HashedModuleIdsPlugin({
// hashFunction: 'sha256',
// hashDigest: 'hex',
// hashDigestLength: 20,
// }),
],
performance: {
assetFilter: function assetFilter(assetFilename) {
return !/(\.map$)|(^(main\.|favicon\.))/.test(assetFilename);
}
}
});