webpack-clean-plugin
raw JSON → 0.2.3 verified Sat Apr 25 auth: no javascript deprecated
A Webpack plugin for removing files and folders during the build process. Version 0.2.3, last release unknown (likely deprecated). Provides simple cleaning functionality on specified build hooks. Minimal configuration: only 'on' and 'path' options. Limited to removing files/folders, with no glob support, logging, or dry-run. Replaced by more modern tools like 'clean-webpack-plugin' or 'webpack-remove-files'.
Common errors
error Error: Cannot find module 'webpack-clean-plugin' ↓
cause Package not installed.
fix
npm install webpack-clean-plugin --save-dev
error TypeError: WebpackCleanPlugin is not a constructor ↓
cause Incorrect import or require statement.
fix
Use 'const { WebpackCleanPlugin } = require('webpack-clean-plugin');'
error No output files deleted ↓
cause Incorrect 'path' option (e.g., relative path not resolved) or wrong hook.
fix
Ensure path is absolute or relative to project root; use 'emit' hook.
Warnings
deprecated Package is unmaintained; last release 2016. Use clean-webpack-plugin or webpack-remove-files instead. ↓
fix Migrate to 'clean-webpack-plugin' (npm install clean-webpack-plugin --save-dev) and replace plugin import and instantiation.
gotcha The 'on' option expects a Webpack hook name (e.g., 'emit', 'compilce' (typo)) but is case-sensitive; 'compilce' is documented but likely a typo for 'compile'. ↓
fix Use 'emit' or 'compile' for proper hook name.
gotcha Plugin does not support glob patterns; only literal paths. Attempting to use globs will delete nothing. ↓
fix Use clean-webpack-plugin with 'patterns' option or specify exact paths.
gotcha Removal is synchronous and blocks Webpack; may cause issues on large builds. ↓
fix Switch to clean-webpack-plugin which supports async cleanup.
Install
npm install webpack-clean-plugin yarn add webpack-clean-plugin pnpm add webpack-clean-plugin Imports
- WebpackCleanPlugin wrong
const WebpackCleanPlugin = require('webpack-clean-plugin');correctconst { WebpackCleanPlugin } = require('webpack-clean-plugin'); - plugin instance wrong
new webpackCleanPlugin({ on: 'emit', path: ['./dist'] })correctnew WebpackCleanPlugin({ on: 'emit', path: ['./dist'] }) - WebpackCleanPlugin wrong
import WebpackCleanPlugin from 'webpack-clean-plugin';correctimport { WebpackCleanPlugin } from 'webpack-clean-plugin';
Quickstart
const { WebpackCleanPlugin } = require('webpack-clean-plugin');
module.exports = {
entry: './src/index.js',
output: { path: __dirname + '/dist' },
plugins: [
new WebpackCleanPlugin({
on: 'emit',
path: ['./dist']
})
]
};