webpack-clean
raw JSON → 1.2.5 verified Sat Apr 25 auth: no javascript maintenance
A webpack plugin to clean specified files after build. Current stable version is 1.2.5, released sporadically (last update 2020). It deletes specified files (and optionally their .map files) after each webpack build. Differentiators: simple API, optional forceDelete to proceed despite compile errors, and optional removeMaps to auto-delete source maps. Compared to clean-webpack-plugin, it is less maintained but offers direct file specification and force deletion.
Common errors
error TypeError: Cannot read property 'hasOwnProperty' of undefined ↓
cause Bug with webpack 4.43.0 in versions <=1.2.4
fix
Update webpack-clean to 1.2.5.
error DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead ↓
cause Using old plugin API in webpack 4.
fix
Update to webpack-clean 1.2.2+ or use a different clean plugin.
error Error: Cannot find module 'winston-color' ↓
cause Missing dependency when using npm <5 or manual install.
fix
Ensure webpack-clean 1.2.1+ is installed (winston-color moved to dependencies).
Warnings
gotcha Plugin uses tapable plugin API which is deprecated in webpack 4; may show deprecation warnings. ↓
fix Upgrade to a modern alternative like clean-webpack-plugin.
gotcha forceDelete option disabled by default; compile errors will stop deletion silently (logged to stdout). ↓
fix Set forceDelete: true in options to force deletion even on errors.
deprecated DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead. ↓
fix The fix is included in version 1.2.2+; update to latest.
breaking Cannot read property 'hasOwnProperty' of undefined error with webpack 4.43.0 ↓
fix Upgrade to version 1.2.5.
Install
npm install webpack-clean yarn add webpack-clean pnpm add webpack-clean Imports
- WebpackCleanPlugin wrong
import WebpackCleanPlugin from 'webpack-clean';correctconst WebpackCleanPlugin = require('webpack-clean'); - WebpackCleanPlugin wrong
const WebpackCleanPlugin = require('webpack-clean').default;correctconst { WebpackCleanPlugin } = require('webpack-clean'); - WebpackCleanPlugin
import WebpackCleanPlugin = require('webpack-clean');
Quickstart
const WebpackCleanPlugin = require('webpack-clean');
const path = require('path');
module.exports = {
context: path.join(__dirname, './'),
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
plugins: [
new WebpackCleanPlugin(['dist/test1.js', 'dist/test2.js'], { removeMaps: true })
]
};