Cleaning up the build folder in Webpack

By default, Webpack places new files in the build folder without deleting the previous ones. This is a bit inconvenient. The following plugin will help you clean the folder: clean-webpack-plugin.

Let's install it:

terminalnpm install clean-webpack-plugin --save-dev

We import:

webpack.config.jsimport {CleanWebpackPlugin} from 'clean-webpack-plugin';

Let's turn on:

webpack.config.jsexport default {
  entry: {
    test1: './src/test1.js',
    test2: './src/test2.js',
    test3: './src/test3.js',
  },
  output: {
    filename: '[name].[contenthash].js',
    path: path.resolve('dist'), // required for the plugin to work
  },
  plugins: [
    new CleanWebpackPlugin(),
  ],
};
Задание 1

Install this plugin and check its operation.