-
Notifications
You must be signed in to change notification settings - Fork 137
Description
You most likely do not need any configuration for this plugin to work as expected. Regardless, please take the time to read below.
Relavant:
- webpack's
output.path - node's
process.cwd() - del's pattern matching
Migration
- Use named export
CleanWebpackPlugin:
// es modules
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
// common js
const { CleanWebpackPlugin } = require('clean-webpack-plugin');- If using basic config
new CleanWebpackPlugin(['dist']), simply remove['dist']and everything will work as expected. Otherwise read carefully below.
Defaults
-
All files inside webpack's
output.pathdirectory will be removed, but the directory itself will not be. If using webpack 4+'s default configuration, this means everything under<PROJECT_DIR>/dist/. UsecleanOnceBeforeBuildPatternsto override this behavior. -
During rebuilds, all webpack assets that are not used anymore will be removed automatically.
Options:
-
cleanOnceBeforeBuildPatterns: Runs before webpack emits files tooutput.path. This happens once during the initial webpack build, but not rebuilds. Will run regardless of webpack errors. -
cleanAfterEveryBuildPatterns: Runs after webpack has completed build. Happens after initial webpack build and after every subsequent successful rebuild. Will not run if any webpack errors are detected.
IMPORTANT:
cleanOnceBeforeBuildPatternsand/orcleanAfterEveryBuildPatternspatterns are relative to webpack'soutput.path. If outsideoutput.path, use an absolute pathpath.join(process.cwd(), 'build/**/*')and run first withdry: trueto ensure nothing unexpected is deleted.
-
cleanStaleWebpackAssets: Automatically remove unused webpack assets on rebuilds. -
protectWebpackAssets: Do not allow custom pattern matching found incleanAfterEveryBuildPatternsto remove current webpack assets. -
dry: Only report files to be removed but do not actually delete any files. -
verbose: Report files that were removed. -
dangerouslyAllowCleanPatternsOutsideProject: Should only be used if removing files usingcleanOnceBeforeBuildPatternsand/orcleanAfterEveryBuildPatternsoutside ofprocess.cwd(). Be very careful with this option. You can permanently delete more than just your project files.
Outdated v1 options:
-
paths: UsecleanOnceBeforeBuildPatternsand/orcleanAfterEveryBuildPatterns. -
beforeEmit: UsecleanOnceBeforeBuildPatternsand/orcleanAfterEveryBuildPatterns. -
exclude: Use!negativepattern matching withcleanOnceBeforeBuildPatternsand/orcleanAfterEveryBuildPatterns. -
watch: Not needed. UsecleanAfterEveryBuildPatternsto remove non-webpack files after rebuild. -
allowExternal: Renamed todangerouslyAllowCleanPatternsOutsideProject. You most likely do not need this option with versionv2because it checks againstprocess.cwd()rather than plugin optionroot. -
root: No longer used.