美文网首页
' CleanWebpackPlugin is not a co

' CleanWebpackPlugin is not a co

作者: 骨朵a | 来源:发表于2019-06-10 14:46 被阅读0次

webpack报错CleanWebpackPlugin is not a constructor

今天初始化项目时,报了这个一个错
CleanWebpackPlugin is not a constructor,刚开始以为是包下载的问题,重装后发现还是出现这样的问题,翻了官方文档发现用法变了,而中文文档还没有更新过来。

之前的用法

  const path = require('path');
  const HtmlWebpackPlugin = require('html-webpack-plugin');
+ const CleanWebpackPlugin = require('clean-webpack-plugin');

  module.exports = {
    entry: {
      app: './src/index.js',
      print: './src/print.js'
    },
    plugins: [
+     new CleanWebpackPlugin(['dist']),
      new HtmlWebpackPlugin({
        title: 'Output Management'
      })
    ],
    output: {
      filename: '[name].bundle.js',
      path: path.resolve(__dirname, 'dist')
    }
  };

现在的用法

const { CleanWebpackPlugin } = require('clean-webpack-plugin');
 
const webpackConfig = {
    plugins: [
        /**
         * All files inside webpack's output.path directory will be removed once, but the
         * directory itself will not be. If using webpack 4+'s default configuration,
         * everything under <PROJECT_DIR>/dist/ will be removed.
         * Use cleanOnceBeforeBuildPatterns to override this behavior.
         *
         * During rebuilds, all webpack assets that are not used anymore
         * will be removed automatically.
         *
         * See `Options and Defaults` for information
         */
        new CleanWebpackPlugin(),
    ],
};
 
module.exports = webpackConfig;

相关文章

网友评论

      本文标题:' CleanWebpackPlugin is not a co

      本文链接:https://www.haomeiwen.com/subject/bnllaxtx.html