Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A webpack plugin to remove your build folder(s) before building

License

NotificationsYou must be signed in to change notification settings

johnagan/clean-webpack-plugin

Repository files navigation

npmMIT LicenseLinux Build StatusWindows Build StatusCoveralls Status

A webpack plugin to remove/clean your build folder(s).

NOTE: Node v10+ and webpack v4+ are supported and tested.

About

By default, this plugin will remove all files inside webpack'soutput.path directory, as well as all unused webpack assets after every successful rebuild.

Coming fromv1? Please read aboutadditional v2 information.

Installation

npm install --save-dev clean-webpack-plugin

Usage

const{ CleanWebpackPlugin}=require('clean-webpack-plugin');constwebpackConfig={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         */newCleanWebpackPlugin(),],};module.exports=webpackConfig;

Options and Defaults (Optional)

newCleanWebpackPlugin({// Simulate the removal of files//// default: falsedry:true,// Write Logs to Console// (Always enabled when dry is true)//// default: falseverbose:true,// Automatically remove all unused webpack assets on rebuild//// default: truecleanStaleWebpackAssets:false,// Do not allow removal of current webpack assets//// default: trueprotectWebpackAssets: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: falsedangerouslyAllowCleanPatternsOutsideProject:true,});

Example Webpack Config

This is a modified version ofWebPack's Plugin documentation that includes the Clean Plugin.

const{ CleanWebpackPlugin}=require('clean-webpack-plugin');// installed via npmconstHtmlWebpackPlugin=require('html-webpack-plugin');// installed via npmconstwebpack=require('webpack');// to access built-in pluginsconstpath=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:[newwebpack.ProgressPlugin(),newCleanWebpackPlugin(),newHtmlWebpackPlugin({template:'./src/index.html'}),],};

About

A webpack plugin to remove your build folder(s) before building

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors25


[8]ページ先頭

©2009-2025 Movatter.jp