diff --git a/CHANGELOG.md b/CHANGELOG.md
index de7fc10..b98a8ec 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,8 +1,12 @@
-## 0.7.3 (Jan 30, 2022) The last stable version
+## 0.8.0 (2022-04-01) The last stable version
+- added new option `remove` to define custom RegExp for generated assets that must be removed
+- update packages
+
+## 0.7.3 (2022-01-30)
- added color verbose output via ANSI color library - ansis
- added the test case for styles imported from javascript
-## 0.7.2 (Dec 13, 2021)
+## 0.7.2 (2021-12-13)
- added new option `enable` to enable / disable the plugin, e.g. by development
- added supports of `RegExp` for option `extensions`
- remove deprecated option `silent`, use `verbose` to show process information (no braking change)
@@ -10,11 +14,11 @@
- update packages
- update readme
-## 0.7.1 (Jan 14, 2021)
+## 0.7.1 (2021-01-14)
### Bugfixes
- fix the issue infinite recursion by collect of resources from dependency modules by usage in react app some big components with many thousands dependencies
-## 0.7.0 (Dec 21, 2020)
+## 0.7.0 (2020-12-21)
### Breaking change
- deprecate the `silent` option, it will be removed on Juni 30, 2021. Use option `verbose: true` to show in console each removed empty file. Defaults, `verbose: false`.
@@ -25,7 +29,7 @@
- webpack setting `externals.jquery: 'jQuery'` or other external libs
- The issue if first in webpack entries are a styles and then a scripts.
-## 0.6.4 (Dec 19, 2020)
+## 0.6.4 (2020-12-19)
- fix the error: `Maximum call stack size exceeded` with webpack setting `optimization.concatenateModules: true`and usage in script imports from `react` and `redux`
- added the test case for single style without a scripts in webpack config
- added silent mode in tests to suppress output log info in the console
@@ -34,14 +38,14 @@
- added default value of `ignore` as `['/node_modules/']` to ignore resources from `node_modules` path
- update npm packages.
-## 0.6.3 (Oct 25, 2020)
+## 0.6.3 (2020-10-25)
- fix BREAKING CHANGE in Webpack 5: no more changes should happen to `Compilation.assets`
- update code accord new API
-## 0.6.2 (Oct 24, 2020)
+## 0.6.2 (2020-10-24)
Update npm packages.
-## 0.6.1 (Oct 20, 2020)
+## 0.6.1 (2020-10-20)
The fork of original [webpack-fix-style-only-entries](https://github.com/fqborges/webpack-fix-style-only-entries) (ver. 0.6.0) for support only Webpack 5 and above.
The Webpack 4 is no longer supported.
diff --git a/README.md b/README.md
index 0898207..9c15a10 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-[![npm](https://img.shields.io/npm/v/webpack-remove-empty-scripts/latest?logo=npm&color=brightgreen "npm package")](https://www.npmjs.com/package/webpack-remove-empty-scripts/v/0.7.3)
+[![npm](https://img.shields.io/npm/v/webpack-remove-empty-scripts/latest?logo=npm&color=brightgreen "npm package")](https://www.npmjs.com/package/webpack-remove-empty-scripts/v/0.8.0)
[![node](https://img.shields.io/node/v/webpack-remove-empty-scripts)](https://nodejs.org)
[![node](https://img.shields.io/github/package-json/dependency-version/webdiscus/webpack-remove-empty-scripts/peer/webpack)](https://webpack.js.org/)
[![codecov](https://codecov.io/gh/webdiscus/webpack-remove-empty-scripts/branch/master/graph/badge.svg)](https://codecov.io/gh/webdiscus/webpack-remove-empty-scripts)
@@ -40,11 +40,11 @@ You can find more info by the following issues:
- [mini-css-extract-plugin issue](https://github.com/webpack-contrib/mini-css-extract-plugin/issues/151)
## NEW
-> The `experimental` version [`0.8.0`](https://github.com/webdiscus/webpack-remove-empty-scripts) has **_new improved and fast algorithm_** to detect generated needless empty js files.\
+> The `experimental` version `^1.x.x` has **_new improved and fast algorithm_** to detect generated needless empty js files.\
> Please test your project before using it in production.\
> If you have a problem with the new version, please create a [new issue](https://github.com/webdiscus/webpack-remove-empty-scripts/issues).
-> :warning: The last stable release is `0.7.3` in the branch [`stable`](https://github.com/webdiscus/webpack-remove-empty-scripts/tree/stable).
+> :warning: The last stable release is `0.8.0` in the branch [`master`](https://github.com/webdiscus/webpack-remove-empty-scripts/tree/master).
## Propose
If you use the `mini-css-extract-plugin` only to extract `css` files from styles defined in webpack entry
@@ -129,11 +129,16 @@ Enable / disable the plugin.
### `extensions`
Type: `RegExp` Default: `/\.(css|scss|sass|less|styl)([?].*)?$/`
Note: the Regexp should have the query part at end `([?].*)?$` to match assets like `style.css?key=val`
-Type: `string[]` Default: `['css', 'scss', 'sass', 'less', 'styl']`. It is automatically converted to type `RegExp`.
+Type: `string[]` Default: `['css', 'scss', 'sass', 'less', 'styl']`. It is automatically converted to type `RegExp`. \
+Search for empty js files in source files only with these extensions.
### `ignore`
Type: `string | RegExp | string[] | RegExp[]` Default: `null`
-Match resource path to be ignored.
+Ignore source files.
+
+### `remove`
+Type: `RegExp` Default: `/\.(js|mjs)$/`
+Remove generated scripts.
### `verbose`
Type: `boolean` Default: `false`
@@ -165,6 +170,11 @@ Give an especial extension to your file, for example `.css.js`:
new RemoveEmptyScriptsPlugin({ extensions: /\.(css.js)$/ })
```
+### Remove generated scripts `*.js` `*.mjs` except `*.rem.js` `*.rem.mjs`
+```JavaScript
+new RemoveEmptyScriptsPlugin({ remove: /(? {
const resourcesCache = [];
compilation.hooks.chunkAsset.tap(plugin, (chunk, filename) => {
- if (!defaultOptions.scriptExtensionsTest.test(filename)) return;
+ if (!removeAssets.test(filename)) return;
const outputPath = compiler.options.output.path;
const chunkGraph = compilation.chunkGraph;
diff --git a/test/cases/option-remove/expected.json b/test/cases/option-remove/expected.json
new file mode 100644
index 0000000..3730290
--- /dev/null
+++ b/test/cases/option-remove/expected.json
@@ -0,0 +1,5 @@
+[
+ "style.css",
+ "style.rem.css",
+ "style.rem.js"
+]
\ No newline at end of file
diff --git a/test/cases/option-remove/style.css b/test/cases/option-remove/style.css
new file mode 100644
index 0000000..9054080
--- /dev/null
+++ b/test/cases/option-remove/style.css
@@ -0,0 +1,3 @@
+h1 {
+ color: red;
+}
\ No newline at end of file
diff --git a/test/cases/option-remove/webpack.config.js b/test/cases/option-remove/webpack.config.js
new file mode 100644
index 0000000..fdc5173
--- /dev/null
+++ b/test/cases/option-remove/webpack.config.js
@@ -0,0 +1,27 @@
+const WebpackRemoveEmptyScripts = require('../../../src/index.js');
+
+const MiniCssExtractPlugin = require('mini-css-extract-plugin');
+
+module.exports = {
+ entry: {
+ 'style': './style.css',
+ 'style.rem': './style.css',
+ },
+ module: {
+ rules: [
+ {
+ test: /\.css$/,
+ use: [MiniCssExtractPlugin.loader, 'css-loader'],
+ },
+ ],
+ },
+ plugins: [
+ new WebpackRemoveEmptyScripts({
+ verbose: true,
+ remove: /(? {
rimraf.sync(path.join(__dirname, 'output'));