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 = require('clean-webpack-plugin')
{
plugins: [
new CleanWebpackPlugin(paths [, {options}])
]
}
Example Webpack Config
This is a modified version of WebPack's Plugin documentation that includes the Clean Plugin.
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const path = require('path');
let pathsToClean = [
'dist',
'build'
]
let cleanOptions = {
root: '/full/webpack/root/path',
exclude: ['shared.js'],
verbose: true,
dry: false
}
const webpackConfig = {
entry: './path/to/my/entry/file.js',
output: {
filename: 'my-first-webpack.bundle.js',
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
loader: 'babel-loader'
}
]
},
plugins: [
new CleanWebpackPlugin(pathsToClean, cleanOptions),
new webpack.optimize.UglifyJsPlugin(),
new HtmlWebpackPlugin({template: './src/index.html'})
]
}
Paths (Required)
An [array] of string paths to clean
[
'dist',
'build/*.*',
'web/*.js'
]
Options and defaults (Optional)
{
root: __dirname,
verbose: true,
dry: false,
watch: false,
exclude: [ 'files', 'to', 'ignore' ],
allowExternal: false
beforeEmit: false
}