Clean plugin for webpack
A webpack plugin to remove/clean your build folder(s).
NOTE: Node v6+ and Webpack v2+ are supported and tested.
About
By default, this plugin will remove all files inside webpack's output.path
directory, as well as all unused webpack assets after every successful rebuild.
Coming from v1
? Please read about additional v2 information.
Installation
npm install --save-dev clean-webpack-plugin
Usage
const CleanWebpackPlugin = require('clean-webpack-plugin');
const webpackConfig = {
plugins: [
new CleanWebpackPlugin(),
],
};
module.exports = webpackConfig;
Options and Defaults (Optional)
new CleanWebpackPlugin({
dry: true,
verbose: true,
cleanStaleWebpackAssets: false,
protectWebpackAssets: false,
cleanOnceBeforeBuildPatterns: ['**/*', '!static-files*'],
cleanOnceBeforeBuildPatterns: [],
cleanAfterEveryBuildPatterns: ['static*.*', '!static1.js'],
dangerouslyAllowCleanPatternsOutsideProject: true,
});
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');
module.exports = {
entry: './path/to/my/entry/file.js',
output: {
path: path.resolve(process.cwd(), 'dist'),
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
},
],
},
plugins: [
new webpack.ProgressPlugin(),
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({ template: './src/index.html' }),
],
};