尝试创建迁移指南中建议的 commonsChunkPlugin 翻译。
我从 vue-cli 生成的块中得到了这个:
plugins: [ new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks (module) {
// any required modules inside node_modules are extracted to vendor
return (
module.resource &&
/\.js$/.test(module.resource) &&
module.resource.indexOf(
path.join(__dirname, '../node_modules')
) === 0
)
}
}),
// extract webpack runtime and module manifest to its own file in order to
// prevent vendor hash from being updated whenever app bundle is updated
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
minChunks: Infinity
}),
// This instance extracts shared chunks from code splitted chunks and bundles them
// in a separate chunk, similar to the vendor chunk
// see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunk
new webpack.optimize.CommonsChunkPlugin({
name: 'app',
async: 'vendor-async',
children: true,
minChunks: 3
})
Run Code Online (Sandbox Code Playgroud)
...
我已经翻译成这个(这是行不通的):
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
name: 'vendor',
test: path.resolve(__dirname, "node_modules"),
enforce: true,
chunks: "initial"
},
manifest: {
chunks: "initial",
minChunks: Infinity,
name: "manifest",
enforce: true
},
app: {
chunks: "initial",
name: 'app',
minChunks: 3
}
}
}
Run Code Online (Sandbox Code Playgroud)
}
但我不知道如何调试它。
编辑:根据评论的查询,我已将所有内容转储到以下公共要点中。这是由 vue-cli 生成的 webpack 3 的原始 webpack 配置。我正在尝试迁移到 webpack 4,但它会影响配置,例如,commonsChunkPlugin 不存在,以及其他更改。
小智 0
我遇到了完全相同的问题,我找出了node_modules文件夹和manifest.js文件中的供应商文件,但是供应商异步,所以我检查了webpack 3版本,构建了它,并且块没有区别,所以我跳过了供应商异步部分,我希望我会帮你的
optimization: {
runtimeChunk: {
name: 'manifest'
},
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/].*\.js$/,
name: 'vendor',
chunks: 'initial',
enforce: true,
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
884 次 |
| 最近记录: |