config.optimization.splitChunks({
cacheGroups: {
// 公共部分打包
vendors: {
name: 'chunk-vendors',
minChunks: 4,
test: /node_modules/,
priority: -10,
chunks: 'initial'
},
// 单独第三方依赖打包
yt:{
name: 'chunk-yt',
minChunks: 1,
test: /[\\/]node_modules[\\/]@xx[\\/]yt-xxx[\\/]/, // 依赖的路径
priority: 10,
chunks: 'initial',
reuseExistingChunk: true
}
}
})
页面配置entry时记得配上chunks:
function getEntry (globPath) {
let entries = {}
glob.sync(globPath).forEach(function (entry) {
var tmp = entry.split('/').splice(-3)
entries[tmp[1]] = {
entry: 'src/' + tmp[0] + '/' + tmp[1] + '/' + 'index.js',
template: 'src/' + tmp[0] + '/' + tmp[1] + '/' + 'index.html',
filename: tmp[1] + '.html',
chunks: ['chunk-yt','chunk-vendors',tmp[1]]
}
})
return entries
}