Skip to content

Commit

Permalink
by default remove all files once prior to compilation, add allowExter…
Browse files Browse the repository at this point in the history
…nal option, migrate dryRun to dry
  • Loading branch information
chrisblossom committed Mar 4, 2019
1 parent 2b94838 commit 8167328
Show file tree
Hide file tree
Showing 3 changed files with 423 additions and 281 deletions.
98 changes: 53 additions & 45 deletions README.md
Expand Up @@ -28,42 +28,14 @@ A webpack plugin to remove/clean your build folder(s).
```js
const CleanWebpackPlugin = require('clean-webpack-plugin');

// webpack config
module.exports = {
const webpackConfig = {
plugins: [
new CleanWebpackPlugin(
// See Options and Defaults
{},
),
],
};
```

## Example Webpack Config

This is a modified version of [WebPack's Plugin documentation](https://webpack.js.org/concepts/plugins/) that includes the Clean Plugin.

```js
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

module.exports = {
entry: './path/to/my/entry/file.js',
module: {
rules: [
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
},
],
},
plugins: [
new webpack.ProgressPlugin(),
// See Options and Defaults
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({ template: './src/index.html' }),
],
};

module.exports = webpackConfig;
```

### Options and Defaults (Optional)
Expand All @@ -75,11 +47,11 @@ new CleanWebpackPlugin({
*
* default: false
*/
dryRun: true,
dry: true,

/**
* Write Logs to Console
* (Always enabled when dryRun is true)
* (Always enabled when dry is true)
*
* default: false
*/
Expand All @@ -88,16 +60,13 @@ new CleanWebpackPlugin({
/**
* **WARNING**
*
* Notes on the below options customPatterns and initialPatterns:
*
* Neither of these options are recommended.
* Use only if you know what you are doing.
* Notes for the below options:
*
* They are unsafe...so test initially with dryRun: true.
* 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(), '')
* use full path. path.join(process.cwd(), 'build/**')
*
* These options extend del's pattern matching API.
* See https://github.com/sindresorhus/del#patterns
Expand All @@ -107,22 +76,61 @@ new CleanWebpackPlugin({
/**
* Removes files once prior to Webpack compilation
*
* See Usage example.
*
* NOTE: customPatterns are included with this
*
* default: disabled
* Use !negative patterns to exclude files
*
* default: ['**']
*/
initialPatterns: ['**'],
initialPatterns: ['**', '!static-files*'],
initialPatterns: [], // disables initialPatterns
cleanBeforeBuildPatterns: [],

/**
* Custom pattern matching
*
* Removes files on after every build that match this pattern.
* Removes files on after every build (watch mode) that match this pattern.
* Used for files that are not created directly by Webpack.
*
* Use !negative patterns to exclude files
*
* default: disabled
*/
customPatterns: ['static*.*', '!static1.js'],
cleanAfterBuildPatterns: [],

/**
* Allow clean patterns outside of process.cwd()
*
* default: false
*/
allowExternal: true,
});
```

## Example Webpack Config

This is a modified version of [WebPack's Plugin documentation](https://webpack.js.org/concepts/plugins/) that includes the Clean Plugin.

```js
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

module.exports = {
entry: './path/to/my/entry/file.js',
module: {
rules: [
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
},
],
},
plugins: [
new webpack.ProgressPlugin(),
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({ template: './src/index.html' }),
],
};
```

0 comments on commit 8167328

Please sign in to comment.