htmlnano 2.0.2 → 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.
Files changed (41) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +2 -2
  3. package/docs/docs/010-introduction.md +4 -4
  4. package/docs/docs/020-usage.md +63 -23
  5. package/docs/docs/030-config.md +1 -1
  6. package/docs/docs/050-modules.md +500 -483
  7. package/docs/package-lock.json +289 -95
  8. package/docs/versioned_docs/version-1.1.1/010-introduction.md +4 -4
  9. package/docs/versioned_docs/version-1.1.1/030-config.md +1 -1
  10. package/docs/versioned_docs/version-2.0.0/010-introduction.md +4 -4
  11. package/docs/versioned_docs/version-2.0.0/030-config.md +2 -2
  12. package/index.d.ts +93 -0
  13. package/lib/helpers.js +4 -11
  14. package/lib/htmlnano.js +11 -36
  15. package/lib/modules/collapseAttributeWhitespace.js +11 -12
  16. package/lib/modules/collapseBooleanAttributes.js +33 -9
  17. package/lib/modules/collapseWhitespace.js +17 -19
  18. package/lib/modules/custom.js +0 -3
  19. package/lib/modules/deduplicateAttributeValues.js +3 -5
  20. package/lib/modules/mergeScripts.js +0 -11
  21. package/lib/modules/mergeStyles.js +2 -8
  22. package/lib/modules/minifyConditionalComments.js +4 -15
  23. package/lib/modules/minifyCss.js +5 -16
  24. package/lib/modules/minifyJs.js +8 -28
  25. package/lib/modules/minifyJson.js +2 -3
  26. package/lib/modules/minifySvg.js +13 -5
  27. package/lib/modules/minifyUrls.js +18 -34
  28. package/lib/modules/normalizeAttributeValues.js +85 -2
  29. package/lib/modules/removeAttributeQuotes.js +0 -2
  30. package/lib/modules/removeComments.js +10 -28
  31. package/lib/modules/removeEmptyAttributes.js +6 -6
  32. package/lib/modules/removeOptionalTags.js +9 -46
  33. package/lib/modules/removeRedundantAttributes.js +20 -68
  34. package/lib/modules/removeUnusedCss.js +7 -18
  35. package/lib/modules/sortAttributes.js +10 -25
  36. package/lib/modules/sortAttributesWithLists.js +7 -29
  37. package/lib/presets/ampSafe.js +2 -5
  38. package/lib/presets/max.js +2 -5
  39. package/lib/presets/safe.js +32 -15
  40. package/package.json +9 -15
  41. package/test.js +0 -48
package/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
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
+
5
10
  ## [2.0.2] - 2022-04-06
6
11
 
7
12
  ### Fixed
@@ -247,6 +252,7 @@ Otherwise, you have to adapt the config according to the new [PurgeCSS@3](https:
247
252
  - Remove attributes that contains only white spaces.
248
253
 
249
254
 
255
+ [2.0.2]: https://github.com/posthtml/htmlnano/compare/2.0.2...2.0.3
250
256
  [2.0.2]: https://github.com/posthtml/htmlnano/compare/2.0.1...2.0.2
251
257
  [2.0.1]: https://github.com/posthtml/htmlnano/compare/2.0.0...2.0.1
252
258
  [2.0.0]: https://github.com/posthtml/htmlnano/compare/1.1.1...2.0.0
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@1.1.1]: https://www.npmjs.com/package/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@1.1.1] |
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@1.0.0]: https://www.npmjs.com/package/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@1.0.0] |
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%** |
@@ -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
+ ```
@@ -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., `htmlanorc.json` or `htmlnanorc.js`) or save options to `package.json` with `htmlnano` key.
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: