htmlnano 2.0.1 → 2.0.3
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 +16 -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 +289 -95
- 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 +4 -11
- package/lib/htmlnano.js +37 -55
- 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 +0 -11
- package/lib/modules/mergeStyles.js +2 -8
- package/lib/modules/minifyConditionalComments.js +4 -15
- package/lib/modules/minifyCss.js +5 -16
- package/lib/modules/minifyJs.js +8 -28
- package/lib/modules/minifyJson.js +5 -7
- package/lib/modules/minifySvg.js +13 -4
- package/lib/modules/minifyUrls.js +18 -34
- package/lib/modules/normalizeAttributeValues.js +85 -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 +9 -15
- package/test.js +0 -48
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,20 @@
|
|
|
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
|
+
## [2.0.3] - 2022-11-13
|
|
6
|
+
_To be added._
|
|
7
|
+
Meanwhile you can check [the diff](https://github.com/posthtml/htmlnano/compare/2.0.2...2.0.3).
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## [2.0.2] - 2022-04-06
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
- JSON-LD crash [#182]
|
|
14
|
+
|
|
15
|
+
|
|
5
16
|
## [2.0.1] - 2022-04-04
|
|
17
|
+
**This version contains a critical bug [#182].**
|
|
18
|
+
**Don't use it.**
|
|
6
19
|
|
|
7
20
|
### Changed
|
|
8
21
|
- Speed improvements [#127]
|
|
@@ -239,6 +252,8 @@ Otherwise, you have to adapt the config according to the new [PurgeCSS@3](https:
|
|
|
239
252
|
- Remove attributes that contains only white spaces.
|
|
240
253
|
|
|
241
254
|
|
|
255
|
+
[2.0.2]: https://github.com/posthtml/htmlnano/compare/2.0.2...2.0.3
|
|
256
|
+
[2.0.2]: https://github.com/posthtml/htmlnano/compare/2.0.1...2.0.2
|
|
242
257
|
[2.0.1]: https://github.com/posthtml/htmlnano/compare/2.0.0...2.0.1
|
|
243
258
|
[2.0.0]: https://github.com/posthtml/htmlnano/compare/1.1.1...2.0.0
|
|
244
259
|
[1.1.1]: https://github.com/posthtml/htmlnano/compare/1.1.0...1.1.1
|
|
@@ -266,6 +281,7 @@ Otherwise, you have to adapt the config according to the new [PurgeCSS@3](https:
|
|
|
266
281
|
[0.1.2]: https://github.com/posthtml/htmlnano/compare/0.1.1...0.1.2
|
|
267
282
|
[0.1.1]: https://github.com/posthtml/htmlnano/compare/0.1.0...0.1.1
|
|
268
283
|
|
|
284
|
+
[#182]: https://github.com/posthtml/htmlnano/issues/182
|
|
269
285
|
[#180]: https://github.com/posthtml/htmlnano/issues/180
|
|
270
286
|
[#170]: https://github.com/posthtml/htmlnano/issues/170
|
|
271
287
|
[#168]: https://github.com/posthtml/htmlnano/issues/168
|
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:
|