webpack 打包报错:webpack.optimize.CommonsChunkPlugin has been removed, please use config.optimization...

原因:原来的插件不能用了,这个中文指南,标的是webpack4.7.0,结果这块没更新

注:CommonsChunkPlugin 插件可以将公共的依赖模块提取到已有的入口 chunk 中,或者提取到一个新生成的 chunk。

最终解决办法:

//optimization与entry/plugins同级
optimization: {
        splitChunks: {
            cacheGroups: {
                commons: {
                    name: "commons",
                    chunks: "initial",
                    minChunks: 2
                }
            }
        }
    },

打包成功:


image.png

你可能感兴趣的:(webpack 打包报错:webpack.optimize.CommonsChunkPlugin has been removed, please use config.optimization...)