Clean dist folder before generating a new build

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 ...

Get JavaScript by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.