Skip to content

Commit 9d6cbcb

Browse files
committed
[RELEASE] The last stable release 0.7.2
- add new option `enable` to enable / disable the plugin, e.g. by development - add support of `RegExp` for option `extensions` - remove deprecated option `silent`, use `verbose` to show process information (no braking change) - add GitHub workflow + codecov - color verbose output - update packages - update readme
1 parent 35e77b1 commit 9d6cbcb

File tree

113 files changed

+1718
-12734
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+1718
-12734
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
7+
[test/cases/**.html]
8+
end_of_line = lf
9+
# disable final new line for expected html files
10+
insert_final_newline = false

.github/FUNDING.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These are supported funding model platforms
2+
3+
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4+
patreon: biodiscus
5+
open_collective: # Replace with a single Open Collective username
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay: # Replace with a single Liberapay username
10+
issuehunt: # Replace with a single IssueHunt username
11+
otechie: # Replace with a single Otechie username
12+
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: "[BUG]"
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
If issue is small you can add the code block to commentary.
15+
Preferably, create a bug repository with reproducible problems.
16+
17+
18+
**Expected behavior**
19+
A clear and concise description of what you expected to happen.
20+
21+
**Dev Environment (please complete the following information):**
22+
- OS: [e.g. macOS / Windows 10 / Ubuntu 18]
23+
- Node [e.g. 12 LTS, 14, 16.04]
24+
25+
26+
**Additional context**
27+
Add any other context about the problem here.

.github/workflows/codecov.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Running Code Coverage
2+
3+
on: [ push, pull_request ]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
strategy:
11+
matrix:
12+
node-version: [ 12.x, 14.x, 16.x ]
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v2
17+
with:
18+
fetch-depth: 2
19+
20+
- name: Set up Node.js ${{ matrix.node-version }}
21+
uses: actions/setup-node@v1
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
25+
- name: Install dependencies
26+
run: npm install
27+
28+
- name: Run the tests
29+
run: npm run test:coverage
30+
31+
- name: Submit coverage data to codecov
32+
uses: codecov/codecov-action@v1
33+
with:
34+
token: ${{ secrets.CODECOV_TOKEN }}

.gitignore

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
.DS_Store
12
.idea
2-
build
3+
_ignored
4+
package-lock.json
5+
coverage
6+
coverage.lcov
37
node_modules
4-
test/outputs
8+
public
9+
dist
10+
test/output/

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/test

.prettierrc

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
11
{
2-
"trailingComma": "es5"
2+
"printWidth": 120,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"singleQuote": true,
6+
"trailingComma": "es5",
7+
"semi": true,
8+
"endOfLine": "lf",
9+
"bracketSpacing": true,
10+
"arrowParens": "always",
11+
"bracketSameLine": true,
12+
"overrides": [
13+
{
14+
"files": ["*.html"],
15+
"options": {
16+
"tabWidth": 4
17+
}
18+
}
19+
]
320
}

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 0.7.2 (Dec 13, 2021) The last stable version
2+
- add new option `enable` to enable / disable the plugin, e.g. by development
3+
- add support of `RegExp` for option `extensions`
4+
- remove deprecated option `silent`, use `verbose` to show process information (no braking change)
5+
- add GitHub workflow + codecov
6+
- color verbose output
7+
- update packages
8+
- update readme
9+
110
## 0.7.1 (Jan 14, 2021)
211
### Bugfixes
312
- The issue infinite recursion by collect of resources from dependency modules by usage in react app some big components with many thousands dependencies.
@@ -64,4 +73,4 @@ Being overly careful here, this version is not breaking for almost all the exist
6473
- added LICENSE.txt ([220e20](https://github.com/fqborges/webpack-fix-style-only-entries/commit/220e20eeb9bc95652a942812a424aadd92ec7d1f))
6574

6675
## 0.4.0 (Sep 8, 2019)
67-
- feat: add support for module js files (PR [#21](https://github.com/fqborges/webpack-fix-style-only-entries/pull/21))
76+
- feat: add support for module js files (PR [#21](https://github.com/fqborges/webpack-fix-style-only-entries/pull/21))

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ISC License
22

3+
Copyright (c) 2021, webdiscus
34
Copyright (c) 20218-2020, fqborges
4-
Copyright (c) 2020, webdiscus
55

66
Permission to use, copy, modify, and/or distribute this software for any
77
purpose with or without fee is hereby granted, provided that the above
@@ -13,4 +13,4 @@ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1313
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1414
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1515
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16-
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

README.md

Lines changed: 154 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,95 @@
1-
[![npm version](https://badge.fury.io/js/webpack-remove-empty-scripts.svg)](https://www.npmjs.com/package/webpack-remove-empty-scripts)
1+
[![npm version](https://badge.fury.io/js/webpack-remove-empty-scripts.svg?v/0.7.2)](https://www.npmjs.com/package/webpack-remove-empty-scripts/v/0.7.2)
2+
[![node](https://img.shields.io/node/v/webpack-remove-empty-scripts)](https://nodejs.org)
3+
[![node](https://img.shields.io/github/package-json/dependency-version/webdiscus/webpack-remove-empty-scripts/peer/webpack)](https://webpack.js.org/)
4+
[![codecov](https://codecov.io/gh/webdiscus/webpack-remove-empty-scripts/branch/master/graph/badge.svg)](https://codecov.io/gh/webdiscus/webpack-remove-empty-scripts)
5+
[![node](https://img.shields.io/npm/dm/webpack-remove-empty-scripts)](https://www.npmjs.com/package/webpack-remove-empty-scripts)
26

37
# [webpack-remove-empty-scripts](https://www.npmjs.com/package/webpack-remove-empty-scripts)
48

59

6-
The plugin remove empty scripts generated by usage only a style (css/scss/sass/less/stylus) without a js script in entry.
10+
The plugin removes empty `js` scripts generated when using only the styles like `css` `scss` `sass` `less` `stylus` in the webpack entry.
711

8-
You can find more info by reading the following issues:
12+
This is improved fork of original plugin [webpack-fix-style-only-entries](https://github.com/fqborges/webpack-fix-style-only-entries) ver. 0.6.0.\
13+
This fork fixes some deprecation messages and some issues in React. See the details in [changelog](https://github.com/webdiscus/webpack-remove-empty-scripts/blob/master/CHANGELOG.md#061-oct-20-2020).
914

10-
- https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/518
11-
- https://github.com/webpack-contrib/mini-css-extract-plugin/issues/151
15+
The plugin support only `Webpack 5`.
16+
For `Webpack 4` use original [plugin](https://github.com/fqborges/webpack-fix-style-only-entries).
1217

13-
This is a fork of original plugin https://github.com/fqborges/webpack-fix-style-only-entries (ver. 0.6.0).
14-
In this fork fixed some deprecation messages and integration tests for Webpack 5. See the details in [changelog](https://github.com/webdiscus/webpack-remove-empty-scripts/blob/master/CHANGELOG.md#061-oct-20-2020).
18+
## Description of the problem
1519

16-
The plugin support only **Webpack 5** using new ChunkGraph and ModuleGraph APIs.
17-
For **Webpack 4** use original [plugin](https://github.com/fqborges/webpack-fix-style-only-entries).
20+
Webpack generates a js file for each resource defined in a webpack entry.
21+
Some extract plugins use webpack entry to define non-js resources.
22+
For example, in webpack entry might be defined resources like js, css, scss, html, pug, etc.
23+
Each resource type needs its own extract plugin and loader. Such a extract plugin should take care of eliminating the phantom js files for non-js resources by self.
24+
But the `mini-css-extract-plugin` not do it.
25+
This plugin fixes this, finds and removes phantom js files for non-js resources.
1826

19-
View on: [GitHub](https://github.com/webdiscus/webpack-remove-empty-scripts), [npmjs](https://www.npmjs.com/package/webpack-remove-empty-scripts)
27+
```js
28+
module.exports = {
29+
entry: {
30+
main: './main.js', // the generated `main.js` is what we expect
31+
styles: './main.scss', // will be generated the expected `styles.css` and the unexpected `styles.js`
32+
},
33+
// ...
34+
}
35+
```
36+
37+
You can find more info by the following issues:
38+
39+
- [extract-text-webpack-plugin issue](https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/518)
40+
- [mini-css-extract-plugin issue](https://github.com/webpack-contrib/mini-css-extract-plugin/issues/151)
41+
42+
## NEW
43+
> The `experimental` version `^0.8.0` has **_new improved and fast algorithm_** to detect generated needless empty js files.\
44+
> Please test your project before using it in production.\
45+
> If you have a problem with the new version, please create a [new issue](https://github.com/webdiscus/webpack-remove-empty-scripts/issues).
46+
47+
> :warning: The last stable release version is `0.7.2` in the branch [`stable`](https://github.com/webdiscus/webpack-remove-empty-scripts/tree/stable).
48+
49+
## Propose
50+
If you use the `mini-css-extract-plugin` only to extract `css` files from styles defined in webpack entry
51+
like `scss` `sass` `less` `stylus` then try to use **new entry extract plugin** - [pug-plugin](https://github.com/webdiscus/pug-plugin).
52+
53+
The `pug-plugin`:
54+
55+
- extract HTML and CSS from `pug` `html` `scss` resources defined in `webpack entry`
56+
- doesn't need any fix plugins like `webpack-remove-empty-scripts`, because it doesn't generate empty `js` files
57+
- is very flexible and fast
58+
59+
Improve performance with `pug-plugin`. Using the `pug-plugin` for `pug` `html` `scss` etc in the `webpack entry` no longer requires additional plugins such as:
60+
- [html-webpack-plugin](https://github.com/jantimon/html-webpack-plugin)
61+
- [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin)
62+
- [webpack-remove-empty-scripts](https://github.com/webdiscus/webpack-remove-empty-scripts) (bug fix plugins for `mini-css-extract-plugin`)
63+
- [pug-loader](https://github.com/webdiscus/pug-loader) (this loader is already included in the `pug-plugin`)
2064

21-
## How to use
22-
Install `npm install -D webpack-remove-empty-scripts`.
65+
For example, `webpack.config.js`
66+
```js
67+
const PugPlugin = require('pug-plugin');
68+
module.exports = {
69+
entry: {
70+
'main': 'main.js',
71+
'styles': 'styles.scss',
72+
'index': 'index.html', // now is possible define HTML file in entry
73+
'page01': 'page01.pug', // now is possible define PUG file in entry
74+
// ...
75+
},
76+
plugins: [
77+
new PugPlugin(), // supports zero config using default webpack output options
78+
]
79+
// ...
80+
};
81+
```
82+
> The plugin can be used not only for `pug` but also for simply extracting `HTML` or `CSS` from `webpack entry`, independent of pug usage.
2383
24-
Require and add to webpack.config plugins.
84+
For more examples see the [pug-plugin](https://github.com/webdiscus/pug-plugin).
85+
86+
## Install
87+
```console
88+
npm install webpack-remove-empty-scripts --save-dev
89+
```
2590

91+
## Usage
92+
The example of webpack.config.js:
2693
```javascript
2794
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
2895
const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts');
@@ -53,28 +120,85 @@ module.exports = {
53120
```
54121

55122
## Options
56-
57-
| Name | Type | Default | Description |
58-
|------------|------------------|-----------------------------------------|-------------|
59-
| verbose | boolean | false | show logs to console |
60-
| extensions | Array[string] | ['css', 'scss', 'sass', 'less', 'styl'] | file extensions for styles |
61-
| ignore | string or RegExp or Array[string] or Array[RegExp] | | match resource path to be ignored |
62-
63-
### Example config:
123+
124+
### `enabled`
125+
Type: `boolean` Default: `true`<br>
126+
Enable / disable the plugin.
127+
**Tip:** Use `disable` for development to improve performance.
128+
129+
### `extensions`
130+
Type: `RegExp` Default: `/\.(css|scss|sass|less|styl)([?].*)?$/`
131+
Note: the Regexp should have the query part at end `([?].*)?$` to match assets like `style.css?key=val` <br>
132+
Type: `string[]` Default: `['css', 'scss', 'sass', 'less', 'styl']`. It is automatically converted to type `RegExp`.
133+
134+
### `ignore`
135+
Type: `string | RegExp | string[] | RegExp[]` Default: `null`<br>
136+
Match resource path to be ignored.
137+
138+
### `verbose`
139+
Type: `boolean` Default: `false`<br>
140+
Show process information.
141+
142+
## Recipes
143+
144+
### Show logs to console by development
64145
```JavaScript
65-
// show logs to console, use it for development
66-
new RemoveEmptyScriptsPlugin({ verbose: true })
146+
const isProduction = process.env.NODE_ENV === 'production';
147+
new RemoveEmptyScriptsPlugin({ verbose: isProduction !== true })
67148
```
68149

150+
### Disable plugin by development to improve performance
69151
```JavaScript
70-
// to identify only 'foo' and 'bar' extensions as styles
71-
new RemoveEmptyScriptsPlugin({ extensions:['foo', 'bar'] })
152+
const isProduction = process.env.NODE_ENV === 'production';
153+
new RemoveEmptyScriptsPlugin({ enabled: isProduction === true })
72154
```
73155

74-
## Recipes
156+
### Identify only `.foo` and `.bar` extensions as styles
157+
158+
```JavaScript
159+
new RemoveEmptyScriptsPlugin({ extensions: /\.(foo|bar)$/ })
160+
```
161+
162+
### Usage a javascript entry to styles
163+
Give an especial extension to your file, for example `.css.js`:
164+
```JavaScript
165+
new RemoveEmptyScriptsPlugin({ extensions: /\.(css.js)$/ })
166+
```
167+
168+
### Recursive ignore all js files from directory, for example `my-workers/`
169+
```JavaScript
170+
new RemoveEmptyScriptsPlugin({
171+
ignore: [
172+
/my-workers\/.+\.js$/,
173+
]
174+
})
175+
```
176+
177+
### Usage webpack-hot-middleware
178+
```JavaScript
179+
new RemoveEmptyScriptsPlugin({
180+
ignore: [
181+
'webpack-hot-middleware',
182+
]
183+
})
184+
```
185+
[See the test case](https://github.com/webdiscus/webpack-remove-empty-scripts/blob/master/test/cases/css-entry-with-ignored-hmr/webpack.config.js).
186+
187+
## Testing
188+
189+
`npm run test` will run the unit and integration tests.\
190+
`npm run test:coverage` will run the tests with coverage.
191+
192+
## Also See
193+
194+
- more examples of usages see in [test cases](https://github.com/webdiscus/pug-plugin/tree/master/test/cases)
195+
- [`pug-plugin`][pug-plugin]
196+
- [`pug-loader`][pug-loader]
75197

76-
### I use a javascript entry to styles:
77-
Give an especial extension to your file (`.css.js` for example) and configure `new RemoveEmptyScriptsPlugin({ extensions:['css.js'] })`.
198+
## License
199+
[ISC](https://github.com/webdiscus/webpack-remove-empty-scripts/blob/master/LICENSE)
78200

79-
### I use webpack-hot-middleware:
80-
Configure this plugin as `new RemoveEmptyScriptsPlugin({ ignore: 'webpack-hot-middleware' })`. See: https://github.com/webdiscus/webpack-remove-empty-scripts/blob/master/test/cases/css-entry-with-ignored-hmr/webpack.config.js
201+
<!-- prettier-ignore-start -->
202+
[pug-plugin]: https://github.com/webdiscus/pug-plugin
203+
[pug-loader]: https://github.com/webdiscus/pug-loader
204+
<!-- prettier-ignore-end -->

0 commit comments

Comments
 (0)