Additional Upgrade Information - Please read before submitting new issues
chrisblossom opened this issue · 2 comments
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.path
directory will be removed, but the directory itself will not be. If using webpack 4+'s default configuration, this means everything under<PROJECT_DIR>/dist/
. UsecleanOnceBeforeBuildPatterns
to 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:
cleanOnceBeforeBuildPatterns
and/orcleanAfterEveryBuildPatterns
patterns are relative to webpack'soutput.path
. If outsideoutput.path
, use an absolute pathpath.join(process.cwd(), 'build/**/*')
and run first withdry: true
to ensure nothing unexpected is deleted.
-
cleanStaleWebpackAssets
: Automatically remove unused webpack assets on rebuilds. -
protectWebpackAssets
: Do not allow custom pattern matching found incleanAfterEveryBuildPatterns
to 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 usingcleanOnceBeforeBuildPatterns
and/orcleanAfterEveryBuildPatterns
outside ofprocess.cwd()
. Be very careful with this option. You can permanently delete more than just your project files.
Outdated v1
options:
-
paths
: UsecleanOnceBeforeBuildPatterns
and/orcleanAfterEveryBuildPatterns
. -
beforeEmit
: UsecleanOnceBeforeBuildPatterns
and/orcleanAfterEveryBuildPatterns
. -
exclude
: Use!negative
pattern matching withcleanOnceBeforeBuildPatterns
and/orcleanAfterEveryBuildPatterns
. -
watch
: Not needed. UsecleanAfterEveryBuildPatterns
to remove non-webpack files after rebuild. -
allowExternal
: Renamed todangerouslyAllowCleanPatternsOutsideProject
. You most likely do not need this option with versionv2
because it checks againstprocess.cwd()
rather than plugin optionroot
. -
root
: No longer used.
@chrisblossom should we close/update?
Updated!