webpack 代码分离
报错信息:
Error: webpack.optimize.CommonsChunkPlugin has been removed, please use config.optimization.splitChunks instead.
问题原因:webpack 4版本废弃了 webpack.optimize.CommonsChunkPlugin
, 但是中文网应用了该代码, 导致出错
解决办法:在webpack.config.js配置文件中
添加
optimization: { //optimization
与entry、plugins
同一级别 splitChunks: { cacheGroups: { commons: { name: "commons", chunks: "initial", minChunks: 2 } } } }