webpack.optimize.CommonsChunkPlugin has been removed, please use config.optimization.splitChunks instead

根本原因:

是项目在升级了webpack到v4.0.0后,打包生产环境文件,报错走不下去。
CommonsChunkPlugin主要是用来提取第三方库和公共模块,避免首屏加载的bundle文件或者按需加载的bundle文件体积过大,从而导致加载时间过长,着实是优化的一把利器。

   解决办法

  1. build/webpack.base.conf.js文件,增加如下代码,与resolve,output平级
optimization: {
  splitChunks: {
    cacheGroups: {
      commons: {
        name: 'commons',
        chunks: 'initial',
        minChunks: 2
      }
    }
  }
}

2.注释一行代码:new webpack.optimize.CommonsChunkPlugin('common.js')

plugins: [
  // new webpack.optimize.CommonsChunkPlugin('common.js'),
  new webpack.ProvidePlugin({
    $:"jquery",
    jQuery:"jquery"
  })
]

转自:https://www.edoou.com/articles/1579673117961699

posted @ 2020-04-27 16:47  vickylinj  阅读(1937)  评论(0编辑  收藏  举报