Research
Security News
Malicious PyPI Package ‘pycord-self’ Targets Discord Developers with Token Theft and Backdoor Exploit
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
clean-webpack-plugin
Advanced tools
The clean-webpack-plugin is a plugin for webpack, a module bundler for JavaScript. It is used to remove/clean your build folder(s) before building. This ensures that only used files are generated when your project is built, preventing the accumulation of outdated files from previous builds.
Removing all files inside webpack's output.path directory
This feature automatically cleans up the output directory specified in webpack's configuration before each build, ensuring that only the files generated in the current build are present.
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
plugins: [
new CleanWebpackPlugin(),
],
};
Preserving specific files or directories during clean
This feature allows you to exclude specific files or directories from being deleted when the output directory is cleaned. This is useful for cases where you want to keep certain files across builds.
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
plugins: [
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: ['**/*', '!static-files*'],
cleanStaleWebpackAssets: false,
protectWebpackAssets: false
}),
],
};
Rimraf is a deep deletion module for node (like `rm -rf`). It's not specifically tied to webpack but can be used in npm scripts or directly in node scripts to clean directories. It's simpler but requires manual configuration compared to clean-webpack-plugin's integration with webpack.
Del is another package for deleting files and directories. Similar to rimraf, it's used in build processes but isn't tied to webpack. It provides more control over what to delete through glob patterns and options but lacks the direct webpack integration that clean-webpack-plugin offers.
A webpack plugin to remove/clean your build folder(s).
NOTE: Node v10+ and webpack v4+ are supported and tested.
By default, this plugin will remove all files inside webpack's output.path
directory, as well as all unused webpack assets after every successful rebuild.
Coming from
v1
? Please read about additional v2 information.
npm install --save-dev clean-webpack-plugin
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const webpackConfig = {
plugins: [
/**
* All files inside webpack's output.path directory will be removed once, but the
* directory itself will not be. If using webpack 4+'s default configuration,
* everything under <PROJECT_DIR>/dist/ will be removed.
* Use cleanOnceBeforeBuildPatterns to override this behavior.
*
* During rebuilds, all webpack assets that are not used anymore
* will be removed automatically.
*
* See `Options and Defaults` for information
*/
new CleanWebpackPlugin(),
],
};
module.exports = webpackConfig;
new CleanWebpackPlugin({
// Simulate the removal of files
//
// default: false
dry: true,
// Write Logs to Console
// (Always enabled when dry is true)
//
// default: false
verbose: true,
// Automatically remove all unused webpack assets on rebuild
//
// default: true
cleanStaleWebpackAssets: false,
// Do not allow removal of current webpack assets
//
// default: true
protectWebpackAssets: false,
// **WARNING**
//
// Notes for the below options:
//
// They are unsafe...so test initially with dry: true.
//
// Relative to webpack's output.path directory.
// If outside of webpack's output.path directory,
// use full path. path.join(process.cwd(), 'build/**/*')
//
// These options extend del's pattern matching API.
// See https://github.com/sindresorhus/del#patterns
// for pattern matching documentation
// Removes files once prior to Webpack compilation
// Not included in rebuilds (watch mode)
//
// Use !negative patterns to exclude files
//
// default: ['**/*']
cleanOnceBeforeBuildPatterns: [
'**/*',
'!static-files*',
'!directoryToExclude/**',
],
cleanOnceBeforeBuildPatterns: [], // disables cleanOnceBeforeBuildPatterns
// Removes files after every build (including watch mode) that match this pattern.
// Used for files that are not created directly by Webpack.
//
// Use !negative patterns to exclude files
//
// default: []
cleanAfterEveryBuildPatterns: ['static*.*', '!static1.js'],
// Allow clean patterns outside of process.cwd()
//
// requires dry option to be explicitly set
//
// default: false
dangerouslyAllowCleanPatternsOutsideProject: true,
});
This is a modified version of WebPack's Plugin documentation that includes the Clean Plugin.
const { CleanWebpackPlugin } = require('clean-webpack-plugin'); // installed via npm
const HtmlWebpackPlugin = require('html-webpack-plugin'); // installed via npm
const webpack = require('webpack'); // to access built-in plugins
const path = require('path');
module.exports = {
entry: './path/to/my/entry/file.js',
output: {
/**
* With zero configuration,
* clean-webpack-plugin will remove files inside the directory below
*/
path: path.resolve(process.cwd(), 'dist'),
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
},
],
},
plugins: [
new webpack.ProgressPlugin(),
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({ template: './src/index.html' }),
],
};
FAQs
A webpack plugin to remove/clean your build folder(s).
The npm package clean-webpack-plugin receives a total of 1,484,658 weekly downloads. As such, clean-webpack-plugin popularity was classified as popular.
We found that clean-webpack-plugin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.