RemoveWebpackPlugin

raw JSON →
1.2.2 verified Sat Apr 25 auth: no javascript

Plugin for webpack to remove directories or files during the build process, similar to rm -r. Current stable version is 1.2.2. The plugin has low release cadence. It is straightforward but offers minimal features compared to alternatives like CleanWebpackPlugin. It supports removing single or multiple paths and configuring error handling (show, hide, fatal). Only works with webpack plugins API.

error TypeError: RemoveWebpackPlugin is not a constructor
cause Using import statement that returns default as an object instead of function.
fix
Use require('remove-webpack-plugin') instead of import.
error Error: ENOENT: no such file or directory, lstat './dist'
cause Removing a path that is not relative to project root or does not exist.
fix
Adjust paths to be relative to the project root, or ensure directories exist.
error Plugin attempted to remove files but nothing happened
cause Plugin may be configured with errors: 'hide' and fails silently.
fix
Use { errors: 'show' } to see error messages.
gotcha Use default export only; named imports will cause errors.
fix Use const RemoveWebpackPlugin = require('remove-webpack-plugin');
gotcha Paths are relative to the project root, not the output directory.
fix Ensure paths like './public/' are correct relative to process.cwd().
gotcha The plugin does not handle glob patterns; specify exact paths.
fix Use CleanWebpackPlugin if glob support is needed.
npm install remove-webpack-plugin
yarn add remove-webpack-plugin
pnpm add remove-webpack-plugin

Shows how to configure RemoveWebpackPlugin to remove multiple directories and suppress warnings.

const RemoveWebpackPlugin = require('remove-webpack-plugin');

module.exports = {
  plugins: [
    new RemoveWebpackPlugin(['./public/', './build/'], { errors: 'hide' })
  ]
}