Clean for WebPack
A webpack plugin to remove/clean your build folder(s) before building
Installation
npm i clean-webpack-plugin --save-dev
Usage
const CleanWebpackPlugin = // webpack config plugins: paths options
Example Webpack Config
This is a modified version of WebPack's Plugin documentation that includes the Clean Plugin.
const CleanWebpackPlugin = ; //installed via npmconst HtmlWebpackPlugin = ; //installed via npmconst webpack = ; //to access built-in pluginsconst path = ; // the path(s) that should be cleanedlet pathsToClean = 'dist' 'build' // the clean options to uselet cleanOptions = root: '/full/webpack/root/path' exclude: 'shared.js' verbose: true dry: false // sample WebPack configconst webpackConfig = entry: './path/to/my/entry/file.js' output: filename: 'my-first-webpack.bundle.js' path: path module: rules: test: /\.$/ loader: 'babel-loader' plugins: pathsToClean cleanOptions template: './src/index.html'
Paths (Required)
An [array] of string paths to clean
'dist' // removes 'dist' folder 'build/*.*' // removes all files in 'build' folder 'web/*.js' // removes all JavaScript files in 'web' folder
Options and defaults (Optional)
// Absolute path to your webpack root folder (paths appended to this) // Default: root of your package root: __dirname // Write logs to console. verbose: true // Use boolean "true" to test/emulate delete. (will not remove files). // Default: false - remove files dry: false // If true, remove files on recompile. // Default: false watch: false // Instead of removing whole path recursively, // remove all path's content with exclusion of provided immediate children. // Good for not removing shared files from build directories. exclude: 'files' 'to' 'ignore' // allow the plugin to clean folders outside of the webpack root. // Default: false - don't allow clean folder outside of the webpack root allowExternal: false // perform clean just before files are emitted to the output dir // Default: false beforeEmit: false