【发布时间】:2020-11-22 11:20:52
【问题描述】:
我一直在尝试减小块大小,但没有解决方案。我正在使用 happypack、ForkTsCheckerWebpackPlugin、TerserPlugin 作为最小化工具。
对于性能配置,我正在使用
performance: {
hints: process.env.NODE_ENV === 'production' ? 'error' : false,
maxEntrypointSize: 200 * KILOBYTES,
maxAssetSize: 100 * KILOBYTES,
assetFilter: (fileName) =>
!fileName.endsWith('.css') && !fileName.endsWith('.scss') && !fileName.endsWith('.map'),
}
用于优化配置
optimization: {
runtimeChunk: 'single',
noEmitOnErrors: true,
minimize: true,
splitChunks: {
cacheGroups: {
default: false,
vendors: false,
vendor: {
test: /[\\/]node_modules[\\/]/,
name(module, chunks, cacheGroupKey) {
const moduleFileName = module
.identifier()
.split('/')
.reduceRight((item) => item);
const allChunksNames = chunks.map((item) => item.name).join('~');
return `${cacheGroupKey}-${allChunksNames}-${moduleFileName}`;
},
chunks: 'all',
minChunks: 2,
priority: 20
},
common: {
name: 'common',
minChunks: 2,
chunks: 'async',
priority: 10,
reuseExistingChunk: true,
enforce: true
}
},
},
minimizer: [
new TerserPlugin({
terserOptions: {
parse: {
ecma: 8
},
compress: {
ecma: 5,
warnings: false,
inline: 2
},
mangle: {
safari10: true
},
output: {
ecma: 5,
comments: false,
ascii_only: true
},
},
cache: true,
parallel: true,
sourceMap: isSourceMap,
}),
],
}
这是我得到的输出
只有一大块。我究竟做错了什么?以及如何减小大小并增加块的数量?
谢谢
【问题讨论】:
标签: reactjs typescript webpack webpack-4