htmlnano 2.1.2 → 2.1.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 (186) hide show
  1. package/README.md +53 -12
  2. package/dist/_modules/collapseAttributeWhitespace.d.mts +57 -0
  3. package/dist/_modules/collapseAttributeWhitespace.d.ts +57 -0
  4. package/dist/_modules/collapseAttributeWhitespace.js +296 -0
  5. package/dist/_modules/collapseAttributeWhitespace.mjs +293 -0
  6. package/dist/_modules/collapseBooleanAttributes.d.mts +60 -0
  7. package/dist/_modules/collapseBooleanAttributes.d.ts +60 -0
  8. package/dist/_modules/collapseBooleanAttributes.js +159 -0
  9. package/{lib/modules → dist/_modules}/collapseBooleanAttributes.mjs +39 -57
  10. package/dist/_modules/collapseWhitespace.d.mts +57 -0
  11. package/dist/_modules/collapseWhitespace.d.ts +57 -0
  12. package/dist/_modules/collapseWhitespace.js +172 -0
  13. package/dist/_modules/collapseWhitespace.mjs +170 -0
  14. package/dist/_modules/custom.d.mts +57 -0
  15. package/dist/_modules/custom.d.ts +57 -0
  16. package/dist/_modules/custom.js +22 -0
  17. package/dist/_modules/custom.mjs +20 -0
  18. package/dist/_modules/deduplicateAttributeValues.d.mts +56 -0
  19. package/dist/_modules/deduplicateAttributeValues.d.ts +56 -0
  20. package/dist/_modules/deduplicateAttributeValues.js +38 -0
  21. package/dist/_modules/deduplicateAttributeValues.mjs +36 -0
  22. package/dist/_modules/example.d.mts +59 -0
  23. package/dist/_modules/example.d.ts +59 -0
  24. package/dist/_modules/example.js +67 -0
  25. package/dist/_modules/example.mjs +65 -0
  26. package/dist/_modules/mergeScripts.d.mts +56 -0
  27. package/dist/_modules/mergeScripts.d.ts +56 -0
  28. package/dist/_modules/mergeScripts.js +53 -0
  29. package/dist/_modules/mergeScripts.mjs +51 -0
  30. package/dist/_modules/mergeStyles.d.mts +56 -0
  31. package/dist/_modules/mergeStyles.d.ts +56 -0
  32. package/dist/_modules/mergeStyles.js +42 -0
  33. package/dist/_modules/mergeStyles.mjs +40 -0
  34. package/dist/_modules/minifyConditionalComments.d.mts +56 -0
  35. package/dist/_modules/minifyConditionalComments.d.ts +56 -0
  36. package/dist/_modules/minifyConditionalComments.js +54 -0
  37. package/{lib/modules → dist/_modules}/minifyConditionalComments.mjs +21 -22
  38. package/dist/_modules/minifyCss.d.mts +56 -0
  39. package/dist/_modules/minifyCss.d.ts +56 -0
  40. package/dist/_modules/minifyCss.js +84 -0
  41. package/dist/_modules/minifyCss.mjs +82 -0
  42. package/dist/_modules/minifyJs.d.mts +56 -0
  43. package/dist/_modules/minifyJs.d.ts +56 -0
  44. package/dist/_modules/minifyJs.js +108 -0
  45. package/dist/_modules/minifyJs.mjs +106 -0
  46. package/dist/_modules/minifyJson.d.mts +56 -0
  47. package/dist/_modules/minifyJson.d.ts +56 -0
  48. package/dist/_modules/minifyJson.js +35 -0
  49. package/dist/_modules/minifyJson.mjs +33 -0
  50. package/dist/_modules/minifySvg.d.mts +56 -0
  51. package/dist/_modules/minifySvg.d.ts +56 -0
  52. package/dist/_modules/minifySvg.js +40 -0
  53. package/dist/_modules/minifySvg.mjs +38 -0
  54. package/dist/_modules/minifyUrls.d.mts +56 -0
  55. package/dist/_modules/minifyUrls.d.ts +56 -0
  56. package/dist/_modules/minifyUrls.js +180 -0
  57. package/dist/_modules/minifyUrls.mjs +178 -0
  58. package/dist/_modules/normalizeAttributeValues.d.mts +56 -0
  59. package/dist/_modules/normalizeAttributeValues.d.ts +56 -0
  60. package/dist/_modules/normalizeAttributeValues.js +234 -0
  61. package/dist/_modules/normalizeAttributeValues.mjs +232 -0
  62. package/dist/_modules/removeAttributeQuotes.d.mts +56 -0
  63. package/dist/_modules/removeAttributeQuotes.d.ts +56 -0
  64. package/dist/_modules/removeAttributeQuotes.js +15 -0
  65. package/dist/_modules/removeAttributeQuotes.mjs +13 -0
  66. package/dist/_modules/removeComments.d.mts +58 -0
  67. package/dist/_modules/removeComments.d.ts +58 -0
  68. package/dist/_modules/removeComments.js +83 -0
  69. package/{lib/modules → dist/_modules}/removeComments.mjs +24 -35
  70. package/dist/_modules/removeEmptyAttributes.d.mts +56 -0
  71. package/dist/_modules/removeEmptyAttributes.d.ts +56 -0
  72. package/dist/_modules/removeEmptyAttributes.js +197 -0
  73. package/dist/_modules/removeEmptyAttributes.mjs +195 -0
  74. package/dist/_modules/removeOptionalTags.d.mts +56 -0
  75. package/dist/_modules/removeOptionalTags.d.ts +56 -0
  76. package/dist/_modules/removeOptionalTags.js +190 -0
  77. package/{lib/modules → dist/_modules}/removeOptionalTags.mjs +54 -91
  78. package/dist/_modules/removeRedundantAttributes.d.mts +57 -0
  79. package/dist/_modules/removeRedundantAttributes.d.ts +57 -0
  80. package/dist/_modules/removeRedundantAttributes.js +128 -0
  81. package/{lib/modules → dist/_modules}/removeRedundantAttributes.mjs +43 -59
  82. package/dist/_modules/removeUnusedCss.d.mts +60 -0
  83. package/dist/_modules/removeUnusedCss.d.ts +60 -0
  84. package/dist/_modules/removeUnusedCss.js +134 -0
  85. package/dist/_modules/removeUnusedCss.mjs +132 -0
  86. package/dist/_modules/sortAttributes.d.mts +57 -0
  87. package/dist/_modules/sortAttributes.d.ts +57 -0
  88. package/dist/_modules/sortAttributes.js +102 -0
  89. package/{lib/modules → dist/_modules}/sortAttributes.mjs +39 -58
  90. package/dist/_modules/sortAttributesWithLists.d.mts +56 -0
  91. package/dist/_modules/sortAttributesWithLists.d.ts +56 -0
  92. package/dist/_modules/sortAttributesWithLists.js +118 -0
  93. package/{lib/modules → dist/_modules}/sortAttributesWithLists.mjs +41 -59
  94. package/dist/helpers.js +72 -0
  95. package/dist/helpers.mjs +63 -0
  96. package/dist/index.js +223 -0
  97. package/dist/index.mjs +209 -0
  98. package/dist/presets/ampSafe.js +19 -0
  99. package/{lib → dist}/presets/ampSafe.mjs +6 -4
  100. package/dist/presets/max.js +28 -0
  101. package/{lib → dist}/presets/max.mjs +6 -4
  102. package/dist/presets/safe.js +60 -0
  103. package/{lib → dist}/presets/safe.mjs +13 -20
  104. package/package.json +48 -56
  105. package/.eslintignore +0 -3
  106. package/CHANGELOG.md +0 -409
  107. package/docs/README.md +0 -33
  108. package/docs/babel.config.js +0 -3
  109. package/docs/docs/010-introduction.md +0 -22
  110. package/docs/docs/020-usage.md +0 -117
  111. package/docs/docs/030-config.md +0 -21
  112. package/docs/docs/040-presets.md +0 -75
  113. package/docs/docs/050-modules.md +0 -855
  114. package/docs/docs/060-contribute.md +0 -16
  115. package/docs/docusaurus.config.js +0 -65
  116. package/docs/netlify.toml +0 -4
  117. package/docs/package-lock.json +0 -21630
  118. package/docs/package.json +0 -40
  119. package/docs/sidebars.js +0 -26
  120. package/docs/versioned_docs/version-1.1.1/010-introduction.md +0 -22
  121. package/docs/versioned_docs/version-1.1.1/020-usage.md +0 -77
  122. package/docs/versioned_docs/version-1.1.1/030-config.md +0 -21
  123. package/docs/versioned_docs/version-1.1.1/040-presets.md +0 -75
  124. package/docs/versioned_docs/version-1.1.1/050-modules.md +0 -785
  125. package/docs/versioned_docs/version-1.1.1/060-contribute.md +0 -16
  126. package/docs/versioned_docs/version-2.0.0/010-introduction.md +0 -22
  127. package/docs/versioned_docs/version-2.0.0/020-usage.md +0 -77
  128. package/docs/versioned_docs/version-2.0.0/030-config.md +0 -21
  129. package/docs/versioned_docs/version-2.0.0/040-presets.md +0 -75
  130. package/docs/versioned_docs/version-2.0.0/050-modules.md +0 -838
  131. package/docs/versioned_docs/version-2.0.0/060-contribute.md +0 -16
  132. package/docs/versioned_sidebars/version-1.1.1-sidebars.json +0 -8
  133. package/docs/versioned_sidebars/version-2.0.0-sidebars.json +0 -8
  134. package/docs/versions.json +0 -4
  135. package/index.cjs +0 -11
  136. package/index.d.cts +0 -3
  137. package/index.d.mts +0 -3
  138. package/index.d.ts +0 -94
  139. package/index.mjs +0 -2
  140. package/lib/helpers.cjs +0 -79
  141. package/lib/helpers.mjs +0 -53
  142. package/lib/htmlnano.cjs +0 -202
  143. package/lib/htmlnano.mjs +0 -198
  144. package/lib/modules/collapseAttributeWhitespace.cjs +0 -86
  145. package/lib/modules/collapseAttributeWhitespace.mjs +0 -104
  146. package/lib/modules/collapseBooleanAttributes.cjs +0 -62
  147. package/lib/modules/collapseWhitespace.cjs +0 -100
  148. package/lib/modules/collapseWhitespace.mjs +0 -132
  149. package/lib/modules/custom.cjs +0 -19
  150. package/lib/modules/custom.mjs +0 -16
  151. package/lib/modules/deduplicateAttributeValues.cjs +0 -38
  152. package/lib/modules/deduplicateAttributeValues.mjs +0 -40
  153. package/lib/modules/example.cjs +0 -85
  154. package/lib/modules/example.mjs +0 -75
  155. package/lib/modules/mergeScripts.cjs +0 -54
  156. package/lib/modules/mergeScripts.mjs +0 -56
  157. package/lib/modules/mergeStyles.cjs +0 -38
  158. package/lib/modules/mergeStyles.mjs +0 -36
  159. package/lib/modules/minifyConditionalComments.cjs +0 -47
  160. package/lib/modules/minifyCss.cjs +0 -73
  161. package/lib/modules/minifyCss.mjs +0 -88
  162. package/lib/modules/minifyJs.cjs +0 -103
  163. package/lib/modules/minifyJs.mjs +0 -121
  164. package/lib/modules/minifyJson.cjs +0 -24
  165. package/lib/modules/minifyJson.mjs +0 -21
  166. package/lib/modules/minifySvg.cjs +0 -37
  167. package/lib/modules/minifySvg.mjs +0 -30
  168. package/lib/modules/minifyUrls.cjs +0 -141
  169. package/lib/modules/minifyUrls.mjs +0 -229
  170. package/lib/modules/normalizeAttributeValues.cjs +0 -120
  171. package/lib/modules/normalizeAttributeValues.mjs +0 -140
  172. package/lib/modules/removeAttributeQuotes.cjs +0 -17
  173. package/lib/modules/removeAttributeQuotes.mjs +0 -12
  174. package/lib/modules/removeComments.cjs +0 -86
  175. package/lib/modules/removeEmptyAttributes.cjs +0 -72
  176. package/lib/modules/removeEmptyAttributes.mjs +0 -121
  177. package/lib/modules/removeOptionalTags.cjs +0 -183
  178. package/lib/modules/removeRedundantAttributes.cjs +0 -112
  179. package/lib/modules/removeUnusedCss.cjs +0 -113
  180. package/lib/modules/removeUnusedCss.mjs +0 -122
  181. package/lib/modules/sortAttributes.cjs +0 -98
  182. package/lib/modules/sortAttributesWithLists.cjs +0 -114
  183. package/lib/presets/ampSafe.cjs +0 -18
  184. package/lib/presets/max.cjs +0 -27
  185. package/lib/presets/safe.cjs +0 -65
  186. package/test.js +0 -23
package/docs/package.json DELETED
@@ -1,40 +0,0 @@
1
- {
2
- "name": "htmlnano-docs",
3
- "version": "1.0.0",
4
- "scripts": {
5
- "docusaurus": "docusaurus",
6
- "start": "docusaurus start",
7
- "build": "docusaurus build",
8
- "swizzle": "docusaurus swizzle",
9
- "deploy": "docusaurus deploy",
10
- "clear": "docusaurus clear",
11
- "serve": "docusaurus serve",
12
- "write-translations": "docusaurus write-translations",
13
- "write-heading-ids": "docusaurus write-heading-ids"
14
- },
15
- "dependencies": {
16
- "@docusaurus/core": "2.2.0",
17
- "@docusaurus/preset-classic": "2.2.0",
18
- "@mdx-js/react": "^1.6.21",
19
- "@svgr/webpack": "^6.5.1",
20
- "clsx": "^1.1.1",
21
- "docusaurus-plugin-goatcounter": "^2.0.1",
22
- "file-loader": "^6.2.0",
23
- "prism-react-renderer": "^1.2.1",
24
- "react": "^17.0.1",
25
- "react-dom": "^17.0.1",
26
- "url-loader": "^4.1.1"
27
- },
28
- "browserslist": {
29
- "production": [
30
- ">0.5%",
31
- "not dead",
32
- "not op_mini all"
33
- ],
34
- "development": [
35
- "last 1 chrome version",
36
- "last 1 firefox version",
37
- "last 1 safari version"
38
- ]
39
- }
40
- }
package/docs/sidebars.js DELETED
@@ -1,26 +0,0 @@
1
- /**
2
- * Creating a sidebar enables you to:
3
- - create an ordered group of docs
4
- - render a sidebar for each doc of that group
5
- - provide next/previous navigation
6
-
7
- The sidebars can be generated from the filesystem, or explicitly defined here.
8
-
9
- Create as many sidebars as you want.
10
- */
11
-
12
- module.exports = {
13
- // By default, Docusaurus generates a sidebar from the docs folder structure
14
- tutorialSidebar: [{type: 'autogenerated', dirName: '.'}],
15
-
16
- // But you can create a sidebar manually
17
- /*
18
- tutorialSidebar: [
19
- {
20
- type: 'category',
21
- label: 'Tutorial',
22
- items: ['hello'],
23
- },
24
- ],
25
- */
26
- };
@@ -1,22 +0,0 @@
1
- ---
2
- sidebar_position: 1
3
- slug: /
4
- ---
5
-
6
- # Introduction
7
-
8
- Modular HTML minifier, built on top of the [PostHTML](https://github.com/posthtml/posthtml).
9
- Inspired by [cssnano](http://cssnano.co/).
10
-
11
-
12
- ## [Benchmark](https://github.com/maltsev/html-minifiers-benchmark/blob/master/README.md)
13
- [html-minifier-terser@5.1.1]: https://www.npmjs.com/package/html-minifier-terser
14
- [htmlnano@1.1.1]: https://www.npmjs.com/package/htmlnano
15
-
16
- | Website | Source (KB) | [html-minifier-terser@5.1.1] | [htmlnano@1.1.1] |
17
- |---------|------------:|----------------:|-----------:|
18
- | [stackoverflow.blog](https://stackoverflow.blog/) | 95 | 87 | 82 |
19
- | [github.com](https://github.com/) | 210 | 183 | 171 |
20
- | [en.wikipedia.org](https://en.wikipedia.org/wiki/Main_Page) | 78 | 72 | 72 |
21
- | [npmjs.com](https://www.npmjs.com/features) | 41 | 38 | 36 |
22
- | **Avg. minify rate** | 0% | **9%** | **13%** |
@@ -1,77 +0,0 @@
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
- ## Javascript
25
- ```js
26
- const htmlnano = require('htmlnano');
27
- const options = {
28
- removeEmptyAttributes: false, // Disable the module "removeEmptyAttributes"
29
- collapseWhitespace: 'conservative' // Pass options to the module "collapseWhitespace"
30
- };
31
- // posthtml, posthtml-render, and posthtml-parse options
32
- const postHtmlOptions = {
33
- sync: true, // https://github.com/posthtml/posthtml#usage
34
- lowerCaseTags: true, // https://github.com/posthtml/posthtml-parser#options
35
- quoteAllAttributes: false, // https://github.com/posthtml/posthtml-render#options
36
- };
37
-
38
- htmlnano
39
- // "preset" arg might be skipped (see "Presets" section below for more info)
40
- // "postHtmlOptions" arg might be skipped
41
- .process(html, options, preset, postHtmlOptions)
42
- .then(function (result) {
43
- // result.html is minified
44
- })
45
- .catch(function (err) {
46
- console.error(err);
47
- });
48
- ```
49
-
50
-
51
- ## PostHTML
52
- Just add `htmlnano` as a final plugin:
53
- ```js
54
- const posthtml = require('posthtml');
55
- const options = {
56
- removeComments: false, // Disable the module "removeComments"
57
- collapseWhitespace: 'conservative' // Pass options to the module "collapseWhitespace"
58
- };
59
- const posthtmlPlugins = [
60
- /* other PostHTML plugins */
61
-
62
- require('htmlnano')(options)
63
- ];
64
-
65
- const posthtmlOptions = {
66
- // See PostHTML docs
67
- };
68
-
69
- posthtml(posthtmlPlugins)
70
- .process(html, posthtmlOptions)
71
- .then(function (result) {
72
- // result.html is minified
73
- })
74
- .catch(function (err) {
75
- console.error(err);
76
- });
77
- ```
@@ -1,21 +0,0 @@
1
- # Config
2
-
3
- There are two main ways to configure htmlnano:
4
-
5
- ## Passing options to `htmlnano` directly
6
- This is the way described above in the examples.
7
-
8
- ## Using configuration file
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
- `htmlnano` uses `cosmiconfig`, so refer to [its documentation](https://github.com/davidtheclark/cosmiconfig/blob/main/README.md) for a more detailed description.
11
-
12
- If you want to specify a preset that way, use `preset` key:
13
-
14
- ```json
15
- {
16
- "preset": "max",
17
- }
18
- ```
19
-
20
- Configuration files have lower precedence than passing options to `htmlnano` directly.
21
- So if you use both ways, then the configuration file would be ignored.
@@ -1,75 +0,0 @@
1
- # Presets
2
-
3
- A preset is just an object with modules config.
4
-
5
- Currently the following presets are available:
6
- - [safe](https://github.com/posthtml/htmlnano/blob/master/lib/presets/safe.mjs) — a default preset for minifying a regular HTML in a safe way (without breaking anything)
7
- - [ampSafe](https://github.com/posthtml/htmlnano/blob/master/lib/presets/ampSafe.mjs) - same as `safe` preset but for [AMP pages](https://www.ampproject.org/)
8
- - [max](https://github.com/posthtml/htmlnano/blob/master/lib/presets/max.mjs) - maximal minification (might break some pages)
9
-
10
-
11
- You can use them the following way:
12
- ```js
13
- const htmlnano = require('htmlnano');
14
- const ampSafePreset = require('htmlnano').presets.ampSafe;
15
- const options = {
16
- // Your options
17
- };
18
-
19
- htmlnano
20
- .process(html, options, ampSafePreset)
21
- .then(function (result) {
22
- // result.html is minified
23
- })
24
- .catch(function (err) {
25
- console.error(err);
26
- });
27
- ```
28
-
29
- If you skip `preset` argument [`safe`](https://github.com/posthtml/htmlnano/blob/master/lib/presets/safe.mjs) preset would be used by default.
30
-
31
-
32
- If you'd like to define your very own config without any presets pass an empty object as a preset:
33
- ```js
34
- const htmlnano = require('htmlnano');
35
- const options = {
36
- // Your options
37
- };
38
-
39
- htmlnano
40
- .process(html, options, {})
41
- .then(function (result) {
42
- // result.html is minified
43
- })
44
- .catch(function (err) {
45
- console.error(err);
46
- });
47
- ```
48
-
49
-
50
- You might create also your own presets:
51
- ```js
52
- const htmlnano = require('htmlnano');
53
- // Preset for minifying email templates
54
- const emailPreset = {
55
- mergeStyles: true,
56
- minifyCss: {
57
- safe: true
58
- },
59
- };
60
-
61
- const options = {
62
- // Some specific options
63
- };
64
-
65
- htmlnano
66
- .process(html, options, emailPreset)
67
- .then(function (result) {
68
- // result.html is minified
69
- })
70
- .catch(function (err) {
71
- console.error(err);
72
- });
73
- ```
74
-
75
- Feel free [to submit a PR](https://github.com/posthtml/htmlnano/issues/new) with your preset if it might be useful for other developers as well.