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
        }
      }
    }
  }
 

 

posted @ 2019-02-22 17:09  tracy-ling  阅读(139)  评论(0编辑  收藏  举报