TypeError:webpack.optimize.DedupePlugin不是构造函数

时间:2018-10-16 12:03:24

标签: reactjs webpack

我一直收到错误消息:TypeError:当我尝试使用以下webpack.config.js构建我的React应用程序时,webpack.optimize.DedupePlugin不是构造函数。我正在使用Webpack版本“ ^ 4.0.1”。谢谢。

plugins: [
    new webpack.HotModuleReplacementPlugin()
    // new webpack.DefinePlugin({
    //   'process.env.NODE_ENV': JSON.stringify('production')
    // })
  ],
  optimization: {
    minimize: false,
    minimizer: [
      new webpack.DefinePlugin({
        // <-- key to reducing React's size
        'process.env': {
          NODE_ENV: JSON.stringify('production')
        }
      }),
      new DedupePlugin(), //dedupe similar code
      new UglifyJsPlugin(), //minify everything
      new AggressiveMergingPlugin() //Merge chunks
    ],
    runtimeChunk: true,
    splitChunks: {
      chunks: 'async',
      minSize: 1000,
      minChunks: 2,
      maxAsyncRequests: 5,
      maxInitialRequests: 3,
      name: true,
      cacheGroups: {
        default: {
          minChunks: 1,
          priority: -20,
          reuseExistingChunk: true
        },
        vendors: {
          test: /[\\/]node_modules[\\/]/,
          priority: -10
        }
      }
    }
  }

2 个答案:

答案 0 :(得分:4)

版本4上不再有重复数据删除插件,这就是原因。

答案 1 :(得分:0)

由重复包装检查器-webpack-plugin代替

https://github.com/darrenscerri/duplicate-package-checker-webpack-plugin