webpack之clean-webpack-plugin报错

参考:https://www.cnblogs.com/PasserByOne/p/12084323.html

clean-webpack-plugin新版使用中报错

webpack之clean-webpack-plugin报错

 webpack之clean-webpack-plugin报错

由于之前代码示例都被遗留下来,导致/dist 文件夹相当杂乱。由于配置的改变,webpack 会生成新的文件放置在 /dist 文件夹中,但是 webpack 无法追踪到哪些文件是实际在项目中用到的。

通常,在每次构建前清理 /dist 文件夹,是比较推荐的做法,需要借助clean-webpack-plugin。

1. 安装

npm install clean-webpack-plugin --save-dev

2. 配置文件

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(),
      new HtmlWebpackPlugin({
        title: ‘Output Management‘
      })
    ],
    output: {
      filename: ‘[name].bundle.js‘,
      path: path.resolve(__dirname, ‘dist‘)
    }
  };

相关推荐