htmlnano 2.0.2 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/README.md +2 -2
- package/docs/docs/010-introduction.md +4 -4
- package/docs/docs/020-usage.md +63 -23
- package/docs/docs/030-config.md +1 -1
- package/docs/docs/050-modules.md +500 -483
- package/docs/package-lock.json +7763 -11645
- package/docs/package.json +3 -3
- package/docs/versioned_docs/version-1.1.1/010-introduction.md +4 -4
- package/docs/versioned_docs/version-1.1.1/030-config.md +1 -1
- package/docs/versioned_docs/version-2.0.0/010-introduction.md +4 -4
- package/docs/versioned_docs/version-2.0.0/030-config.md +2 -2
- package/index.d.ts +93 -0
- package/lib/helpers.js +6 -12
- package/lib/htmlnano.js +18 -40
- package/lib/modules/collapseAttributeWhitespace.js +11 -12
- package/lib/modules/collapseBooleanAttributes.js +33 -9
- package/lib/modules/collapseWhitespace.js +17 -19
- package/lib/modules/custom.js +0 -3
- package/lib/modules/deduplicateAttributeValues.js +3 -5
- package/lib/modules/mergeScripts.js +3 -12
- package/lib/modules/mergeStyles.js +5 -9
- package/lib/modules/minifyConditionalComments.js +4 -15
- package/lib/modules/minifyCss.js +9 -16
- package/lib/modules/minifyJs.js +25 -29
- package/lib/modules/minifyJson.js +6 -3
- package/lib/modules/minifySvg.js +17 -9
- package/lib/modules/minifyUrls.js +18 -34
- package/lib/modules/normalizeAttributeValues.js +80 -2
- package/lib/modules/removeAttributeQuotes.js +0 -2
- package/lib/modules/removeComments.js +10 -28
- package/lib/modules/removeEmptyAttributes.js +6 -6
- package/lib/modules/removeOptionalTags.js +9 -46
- package/lib/modules/removeRedundantAttributes.js +20 -68
- package/lib/modules/removeUnusedCss.js +7 -18
- package/lib/modules/sortAttributes.js +10 -25
- package/lib/modules/sortAttributesWithLists.js +7 -29
- package/lib/presets/ampSafe.js +2 -5
- package/lib/presets/max.js +2 -5
- package/lib/presets/safe.js +32 -15
- package/package.json +15 -21
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,33 @@
|
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
|
4
4
|
|
|
5
|
+
|
|
6
|
+
## [2.0.4] - 2023-04-15
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
- Should not minify `<script>` and `<style>` with SRI [#220]
|
|
10
|
+
- Should not merge `<style>` or `<script>` with SRI [#220]
|
|
11
|
+
- Should not minify json with SRI [#220]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [2.0.3] - 2022-11-13
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
- Minify function for `HtmlMinimizerWebpackPlugin`
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
- `collapseWhitespace`: handle textNode when comment is preserved [#184]
|
|
21
|
+
- `minifyUrls`: srcset & javascript: url [#185]
|
|
22
|
+
- Correct missing value default usage
|
|
23
|
+
- `collapseBooleanAttributes`: empty string attributes
|
|
24
|
+
- Guard type of attributes' value [#195]
|
|
25
|
+
- Do not choke on svg error [#197]
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
- Minify based on invalid value default
|
|
29
|
+
- Avoid hardcoding preset keys
|
|
30
|
+
|
|
31
|
+
|
|
5
32
|
## [2.0.2] - 2022-04-06
|
|
6
33
|
|
|
7
34
|
### Fixed
|
|
@@ -247,6 +274,8 @@ Otherwise, you have to adapt the config according to the new [PurgeCSS@3](https:
|
|
|
247
274
|
- Remove attributes that contains only white spaces.
|
|
248
275
|
|
|
249
276
|
|
|
277
|
+
[2.0.4]: https://github.com/posthtml/htmlnano/compare/2.0.3...2.0.4
|
|
278
|
+
[2.0.3]: https://github.com/posthtml/htmlnano/compare/2.0.2...2.0.3
|
|
250
279
|
[2.0.2]: https://github.com/posthtml/htmlnano/compare/2.0.1...2.0.2
|
|
251
280
|
[2.0.1]: https://github.com/posthtml/htmlnano/compare/2.0.0...2.0.1
|
|
252
281
|
[2.0.0]: https://github.com/posthtml/htmlnano/compare/1.1.1...2.0.0
|
|
@@ -275,6 +304,12 @@ Otherwise, you have to adapt the config according to the new [PurgeCSS@3](https:
|
|
|
275
304
|
[0.1.2]: https://github.com/posthtml/htmlnano/compare/0.1.1...0.1.2
|
|
276
305
|
[0.1.1]: https://github.com/posthtml/htmlnano/compare/0.1.0...0.1.1
|
|
277
306
|
|
|
307
|
+
|
|
308
|
+
[#220]: https://github.com/posthtml/htmlnano/issues/220
|
|
309
|
+
[#197]: https://github.com/posthtml/htmlnano/issues/197
|
|
310
|
+
[#195]: https://github.com/posthtml/htmlnano/issues/195
|
|
311
|
+
[#185]: https://github.com/posthtml/htmlnano/issues/185
|
|
312
|
+
[#184]: https://github.com/posthtml/htmlnano/issues/184
|
|
278
313
|
[#182]: https://github.com/posthtml/htmlnano/issues/182
|
|
279
314
|
[#180]: https://github.com/posthtml/htmlnano/issues/180
|
|
280
315
|
[#170]: https://github.com/posthtml/htmlnano/issues/170
|
package/README.md
CHANGED
|
@@ -6,9 +6,9 @@ Modular HTML minifier, built on top of the [PostHTML](https://github.com/posthtm
|
|
|
6
6
|
|
|
7
7
|
## [Benchmark](https://github.com/maltsev/html-minifiers-benchmark/blob/master/README.md)
|
|
8
8
|
[html-minifier-terser@6.0.2]: https://www.npmjs.com/package/html-minifier-terser
|
|
9
|
-
[htmlnano@
|
|
9
|
+
[htmlnano@2.0.0]: https://www.npmjs.com/package/htmlnano
|
|
10
10
|
|
|
11
|
-
| Website | Source (KB) | [html-minifier-terser@6.0.2] | [htmlnano@
|
|
11
|
+
| Website | Source (KB) | [html-minifier-terser@6.0.2] | [htmlnano@2.0.0] |
|
|
12
12
|
|---------|------------:|----------------:|-----------:|
|
|
13
13
|
| [stackoverflow.blog](https://stackoverflow.blog/) | 90 | 82 | 76 |
|
|
14
14
|
| [github.com](https://github.com/) | 232 | 203 | 173 |
|
|
@@ -5,18 +5,18 @@ slug: /
|
|
|
5
5
|
|
|
6
6
|
# Introduction
|
|
7
7
|
|
|
8
|
-
Modular HTML minifier, built on top of the [PostHTML](https://github.com/posthtml/posthtml).
|
|
8
|
+
Modular HTML minifier, built on top of the [PostHTML](https://github.com/posthtml/posthtml).
|
|
9
9
|
Inspired by [cssnano](http://cssnano.co/).
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
## [Benchmark](https://github.com/maltsev/html-minifiers-benchmark/blob/master/README.md)
|
|
13
13
|
[html-minifier-terser@5.1.1]: https://www.npmjs.com/package/html-minifier-terser
|
|
14
|
-
[htmlnano@
|
|
14
|
+
[htmlnano@2.0.0]: https://www.npmjs.com/package/htmlnano
|
|
15
15
|
|
|
16
|
-
| Website | Source (KB) | [html-minifier-terser@5.1.1] | [htmlnano@
|
|
16
|
+
| Website | Source (KB) | [html-minifier-terser@5.1.1] | [htmlnano@2.0.0] |
|
|
17
17
|
|---------|------------:|----------------:|-----------:|
|
|
18
18
|
| [stackoverflow.blog](https://stackoverflow.blog/) | 95 | 87 | 82 |
|
|
19
19
|
| [github.com](https://github.com/) | 210 | 183 | 171 |
|
|
20
20
|
| [en.wikipedia.org](https://en.wikipedia.org/wiki/Main_Page) | 78 | 72 | 72 |
|
|
21
21
|
| [npmjs.com](https://www.npmjs.com/features) | 41 | 38 | 36 |
|
|
22
|
-
| **Avg. minify rate** | 0% | **9%** | **13%** |
|
|
22
|
+
| **Avg. minify rate** | 0% | **9%** | **13%** |
|
package/docs/docs/020-usage.md
CHANGED
|
@@ -1,26 +1,4 @@
|
|
|
1
1
|
# Usage
|
|
2
|
-
|
|
3
|
-
## Gulp
|
|
4
|
-
```bash
|
|
5
|
-
npm install --save-dev gulp-htmlnano
|
|
6
|
-
```
|
|
7
|
-
|
|
8
|
-
```js
|
|
9
|
-
const gulp = require('gulp');
|
|
10
|
-
const htmlnano = require('gulp-htmlnano');
|
|
11
|
-
const options = {
|
|
12
|
-
removeComments: false
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
gulp.task('default', function() {
|
|
16
|
-
return gulp
|
|
17
|
-
.src('./index.html')
|
|
18
|
-
.pipe(htmlnano(options))
|
|
19
|
-
.pipe(gulp.dest('./build'));
|
|
20
|
-
});
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
|
|
24
2
|
## Javascript
|
|
25
3
|
```js
|
|
26
4
|
const htmlnano = require('htmlnano');
|
|
@@ -74,4 +52,66 @@ posthtml(posthtmlPlugins)
|
|
|
74
52
|
.catch(function (err) {
|
|
75
53
|
console.error(err);
|
|
76
54
|
});
|
|
77
|
-
```
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
## Webpack
|
|
59
|
+
|
|
60
|
+
```sh
|
|
61
|
+
npm install html-minimizer-webpack-plugin --save-dev
|
|
62
|
+
npm install htmlnano --save-dev
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
// webpack.config.js
|
|
67
|
+
const HtmlMinimizerWebpackPlugin = require('html-minimizer-webpack-plugin');
|
|
68
|
+
const htmlnano = require('htmlnano');
|
|
69
|
+
|
|
70
|
+
module.exports = {
|
|
71
|
+
optimization: {
|
|
72
|
+
minimize: true,
|
|
73
|
+
minimizer: [
|
|
74
|
+
// For webpack@5 you can use the `...` syntax to extend existing minimizers (i.e. `terser-webpack-plugin`), uncomment the next line
|
|
75
|
+
// `...`,
|
|
76
|
+
new HtmlMinimizerWebpackPlugin({
|
|
77
|
+
// Add HtmlMinimizerWebpackPlugin's option here, see https://webpack.js.org/plugins/html-minimizer-webpack-plugin/#options
|
|
78
|
+
// test: /\.html(\?.*)?$/i,
|
|
79
|
+
|
|
80
|
+
// Use htmlnano as HtmlMinimizerWebpackPlugin's minimizer
|
|
81
|
+
minify: htmlnano.htmlMinimizerWebpackPluginMinify,
|
|
82
|
+
minimizerOptions: {
|
|
83
|
+
// Add htmlnano's option here
|
|
84
|
+
removeComments: false, // Disable the module "removeComments"
|
|
85
|
+
collapseWhitespace: 'conservative' // Pass options to the module "collapseWhitespace"
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
## Gulp
|
|
96
|
+
```bash
|
|
97
|
+
npm i -D gulp-posthtml htmlnano
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
const gulp = require('gulp');
|
|
102
|
+
const posthtml = require('gulp-posthtml');
|
|
103
|
+
const htmlnano = require('htmlnano');
|
|
104
|
+
const options = {
|
|
105
|
+
removeComments: false
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
gulp.task('default', function() {
|
|
109
|
+
return gulp
|
|
110
|
+
.src('./index.html')
|
|
111
|
+
.pipe(posthtml([
|
|
112
|
+
// Add `htmlnano` as a final plugin
|
|
113
|
+
htmlnano(options)
|
|
114
|
+
]))
|
|
115
|
+
.pipe(gulp.dest('./build'));
|
|
116
|
+
});
|
|
117
|
+
```
|
package/docs/docs/030-config.md
CHANGED
|
@@ -6,7 +6,7 @@ There are two main ways to configure htmlnano:
|
|
|
6
6
|
This is the way described above in the examples.
|
|
7
7
|
|
|
8
8
|
## Using configuration file
|
|
9
|
-
Alternatively, you might create a configuration file (e.g., `
|
|
9
|
+
Alternatively, you might create a configuration file (e.g., `htmlnanorc.json` or `htmlnanorc.js`) or save options to `package.json` with `htmlnano` key.
|
|
10
10
|
`htmlnano` uses `cosmiconfig`, so refer to [its documentation](https://github.com/davidtheclark/cosmiconfig/blob/main/README.md) for a more detailed description.
|
|
11
11
|
|
|
12
12
|
If you want to specify a preset that way, use `preset` key:
|