原因
根据官方文档提示:
webpack will automatically split chunks based on these conditions:
New chunk can be shared OR modules are from the node_modules folder
New chunk would be bigger than 30kb (before min+gz)
Maximum number of parallel requests when loading chunks on demand would be lower or equal to 5
Maximum number of parallel requests at initial page load would be lower or equal to 3
默认配置中公共模块的大小要大于30kb或满足其他条件才会进行分离
解决办法
在webpack配置文件中设置 minisize属性,降低打包标准
//... 其他基础配置
optimization: {
splitChunks: {
// 包含所有chunks
chunks: "all",
automaticNameDelimiter: "-",
minSize: 30, // 默认提取出的新chunk在两次压缩(打包压缩和服务器压缩)之前要大于30kb
},
},