johnagan/clean-webpack-plugin

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:

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/. Use cleanOnceBeforeBuildPatterns 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 to output.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/or cleanAfterEveryBuildPatterns patterns are relative to webpack's output.path. If outside output.path, use an absolute path path.join(process.cwd(), 'build/**/*') and run first with dry: true to ensure nothing unexpected is deleted.

  • cleanStaleWebpackAssets: Automatically remove unused webpack assets on rebuilds.

  • protectWebpackAssets: Do not allow custom pattern matching found in cleanAfterEveryBuildPatterns 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 using cleanOnceBeforeBuildPatterns and/or cleanAfterEveryBuildPatterns outside of process.cwd(). Be very careful with this option. You can permanently delete more than just your project files.

Outdated v1 options:

  • paths: Use cleanOnceBeforeBuildPatterns and/or cleanAfterEveryBuildPatterns.

  • beforeEmit: Use cleanOnceBeforeBuildPatterns and/or cleanAfterEveryBuildPatterns.

  • exclude: Use !negative pattern matching with cleanOnceBeforeBuildPatterns and/or cleanAfterEveryBuildPatterns.

  • watch: Not needed. Use cleanAfterEveryBuildPatterns to remove non-webpack files after rebuild.

  • allowExternal: Renamed to dangerouslyAllowCleanPatternsOutsideProject. You most likely do not need this option with version v2 because it checks against process.cwd() rather than plugin option root.

  • root: No longer used.

@chrisblossom should we close/update?

Updated!