Since we generate lot of builds with different hashed filenames, it is a good practice to delete the dist directory before running each build. clean-webpack-plugin does just that. It cleans the dist directory before new files are bundled. To use clean-webpack-plugin, run the following command inside the project root folder to install the plugin: :
npm install -D clean-webpack-plugin
Then, add the following variables to your Webpack configuration file:
const CleanWebpackPlugin = require('clean-webpack-plugin');const pathsToClean = [ 'dist'];const cleanOptions = { root: __dirname, verbose: true, dry: false, exclude: [],};
Finally, add new CleanWebpackPlugin(pathsToClean, cleanOptions) to your ...