htmlnano 2.1.1 → 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 -60
  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 -60
  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 +53 -59
  105. package/.eslintignore +0 -3
  106. package/CHANGELOG.md +0 -398
  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 -21796
  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 -93
  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 -200
  143. package/lib/htmlnano.mjs +0 -196
  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 -99
  182. package/lib/modules/sortAttributesWithLists.cjs +0 -115
  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 -48
@@ -1,785 +0,0 @@
1
- # Modules
2
-
3
- By default the modules should only perform safe transforms, see the module documentation below for details.
4
- You can disable modules by passing `false` as option, and enable them by passing `true`.
5
-
6
-
7
- ### collapseAttributeWhitespace
8
- Collapse redundant white spaces in list-like attributes (`class`, `rel`, `ping`).
9
-
10
- #### Example
11
- Source:
12
- ```html
13
- <a class=" content page " style=" display: block; " href=" https://example.com"></a>
14
- ```
15
-
16
- Minified:
17
- ```html
18
- <a class="content page" style="display: block;" href="https://example.com"></a>
19
- ```
20
-
21
-
22
-
23
- ### collapseWhitespace
24
- Collapses redundant white spaces (including new lines). It doesn’t affect white spaces in the elements `<style>`, `<textarea>`, `<script>` and `<pre>`.
25
-
26
- #### Options
27
- - `conservative` — collapses all redundant white spaces to 1 space (default)
28
- - `aggressive` — collapses all whitespaces that are redundant and safe to remove
29
- - `all` — collapses all redundant white spaces
30
-
31
- #### Side effects
32
-
33
- *all*
34
- `<i>hello</i> <i>world</i>` or `<i>hello</i><br><i>world</i>` after minification will be rendered as `helloworld`.
35
- To prevent that use either the default `conservative` option, or the `aggressive` option.
36
-
37
- #### Example
38
- Source:
39
- ```html
40
- <div>
41
- hello world!
42
- <a href="#">answer</a>
43
- <style>div { color: red; } </style>
44
- <main></main>
45
- </div>
46
- ```
47
-
48
- Minified (with `all`):
49
- ```html
50
- <div>hello world!<a href="#">answer</a><style>div { color: red; } </style><main></main></div>
51
- ```
52
-
53
- Minified (with `aggressive`):
54
- ```html
55
- <div> hello world! <a href="#">answer</a> <style>div { color: red; } </style><main></main></div>
56
- ```
57
-
58
- Minified (with `conservative`):
59
- ```html
60
- <div> hello world! <a href="#">answer</a> <style>div { color: red; } </style> <main></main> </div>
61
- ```
62
-
63
-
64
- ### deduplicateAttributeValues
65
- Remove duplicate values from list-like attributes (`class`, `rel`, `ping`).
66
-
67
- #### Example
68
- Source:
69
- ```html
70
- <div class="sidebar left sidebar"></div>
71
- ```
72
-
73
- Minified:
74
- ```html
75
- <div class="sidebar left"></div>
76
- ```
77
-
78
-
79
- ### removeComments
80
- #### Options
81
- - `safe` – removes all HTML comments except the conditional comments and [`<!--noindex--><!--/noindex-->`](https://yandex.com/support/webmaster/controlling-robot/html.xml) (default)
82
- - `all` — removes all HTML comments
83
- - A `RegExp` — only HTML comments matching the given regexp will be removed.
84
- - A `Function` that returns boolean — removes HTML comments that can make the given callback function returns truthy value.
85
-
86
- #### Example
87
-
88
- Source:
89
-
90
- ```js
91
- {
92
- removeComments: 'all'
93
- }
94
- ```
95
-
96
- ```html
97
- <div><!-- test --></div>
98
- ```
99
-
100
- Minified:
101
-
102
- ```html
103
- <div></div>
104
- ```
105
-
106
- Source:
107
-
108
- ```js
109
- {
110
- removeComments: /<!--(\/)?noindex-->/
111
- }
112
- ```
113
-
114
- ```html
115
- <div><!--noindex-->this text will not be indexed<!--/noindex-->Lorem ipsum dolor sit amet<!--more-->Lorem ipsum dolor sit amet</div>
116
- ```
117
-
118
- Minified:
119
-
120
- ```html
121
- <div>this text will not be indexedLorem ipsum dolor sit amet<!--more-->Lorem ipsum dolor sit amet</div>
122
- ```
123
-
124
- Source:
125
-
126
- ```js
127
- {
128
- removeComments: (comments) => {
129
- if (comments.includes('noindex')) return true;
130
- return false;
131
- }
132
- }
133
- ```
134
-
135
- ```html
136
- <div><!--noindex-->this text will not be indexed<!--/noindex-->Lorem ipsum dolor sit amet<!--more-->Lorem ipsum dolor sit amet</div>
137
- ```
138
-
139
- Minified:
140
-
141
- ```html
142
- <div>this text will not be indexedLorem ipsum dolor sit amet<!--more-->Lorem ipsum dolor sit amet</div>
143
- ```
144
-
145
-
146
- ### removeEmptyAttributes
147
- Removes empty [safe-to-remove](https://github.com/posthtml/htmlnano/blob/master/lib/modules/removeEmptyAttributes.mjs) attributes.
148
-
149
- #### Side effects
150
- This module could break your styles or JS if you use selectors with attributes:
151
- ```CSS
152
- img[style=""] {
153
- margin: 10px;
154
- }
155
- ```
156
-
157
- #### Example
158
- Source:
159
- ```html
160
- <img src="foo.jpg" alt="" style="">
161
- ```
162
-
163
- Minified:
164
- ```html
165
- <img src="foo.jpg" alt="">
166
- ```
167
-
168
- ### removeAttributeQuotes
169
- Remove quotes around attributes when possible, see [HTML Standard - 12.1.2.3 Attributes - Unquoted attribute value syntax](https://html.spec.whatwg.org/multipage/syntax.html#attributes-2).
170
-
171
- #### Example
172
- Source:
173
- ```html
174
- <div class="foo" title="hello world"></div>
175
- ```
176
-
177
- Minified:
178
- ```html
179
- <div class=foo title="hello world"></div>
180
- ```
181
-
182
- #### Notice
183
- The feature is implemented by [posthtml-render's `quoteAllAttributes`](https://github.com/posthtml/posthtml-render#options), which is one of the PostHTML's option. So `removeAttributeQuotes` could be overriden by other PostHTML's plugins and PostHTML's configuration.
184
-
185
- For example:
186
-
187
- ```js
188
- posthtml([
189
- htmlnano({
190
- removeAttributeQuotes: true
191
- })
192
- ]).process(html, {
193
- quoteAllAttributes: true
194
- })
195
- ```
196
-
197
- `removeAttributeQuotes` will not work because PostHTML's `quoteAllAttributes` takes the priority.
198
-
199
- ### removeUnusedCss
200
-
201
- Removes unused CSS inside `<style>` tags with either [uncss](https://github.com/uncss/uncss)
202
- or [PurgeCSS](https://github.com/FullHuman/purgecss).
203
-
204
- #### With uncss
205
-
206
- ##### Options
207
- See [the documentation of uncss](https://github.com/uncss/uncss) for all supported options.
208
-
209
- uncss options can be passed directly to the `removeUnusedCss` module:
210
- ```js
211
- htmlnano.process(html, {
212
- removeUnusedCss: {
213
- ignore: ['.do-not-remove']
214
- }
215
- });
216
- ```
217
-
218
- The following uncss options are ignored if passed to the module:
219
-
220
- - `stylesheets`
221
- - `ignoreSheets`
222
- - `raw`
223
-
224
- #### With PurgeCSS
225
-
226
- Use PurgeCSS instead of uncss by adding `tool: 'purgeCSS'` to the options.
227
-
228
- ##### Options
229
-
230
- See [the documentation of PurgeCSS](https://www.purgecss.com) for all supported options.
231
-
232
- PurgeCSS options can be passed directly to the `removeUnusedCss` module:
233
- ```js
234
- htmlnano.process(html, {
235
- removeUnusedCss: {
236
- tool: 'purgeCSS',
237
- safelist: ['.do-not-remove']
238
- }
239
- });
240
- ```
241
-
242
- The following PurgeCSS options are ignored if passed to the module:
243
-
244
- - `content`
245
- - `css`
246
- - `extractors`
247
-
248
- #### Example
249
- Source:
250
- ```html
251
- <div class="b">
252
- <style>
253
- .a {
254
- margin: 10px 10px 10px 10px;
255
- }
256
- .b {
257
- color: #ff0000;
258
- }
259
- </style>
260
- </div>
261
- ```
262
-
263
- Optimized:
264
- ```html
265
- <div class="b">
266
- <style>
267
- .b {
268
- color: #ff0000;
269
- }
270
- </style>
271
- </div>
272
- ```
273
-
274
-
275
- ### minifyCss
276
- Minifies CSS with [cssnano](http://cssnano.co/) inside `<style>` tags and `style` attributes.
277
-
278
- #### Options
279
- See [the documentation of cssnano](http://cssnano.co/optimisations/) for all supported optimizations.
280
- By default CSS is minified with preset `default`, which shouldn't have any side-effects.
281
-
282
- To use another preset or disabled some optimizations pass options to `minifyCss` module:
283
- ```js
284
- htmlnano.process(html, {
285
- minifyCss: {
286
- preset: ['default', {
287
- discardComments: {
288
- removeAll: true,
289
- },
290
- }]
291
- }
292
- });
293
- ```
294
-
295
- #### Example
296
- Source:
297
- ```html
298
- <div>
299
- <style>
300
- h1 {
301
- margin: 10px 10px 10px 10px;
302
- color: #ff0000;
303
- }
304
- </style>
305
- </div>
306
- ```
307
-
308
- Minified:
309
- ```html
310
- <div>
311
- <style>h1{margin:10px;color:red}</style>
312
- </div>
313
- ```
314
-
315
-
316
- ### minifyJs
317
- Minifies JS using [Terser](https://github.com/fabiosantoscode/terser) inside `<script>` tags.
318
-
319
- #### Options
320
- See [the documentation of Terser](https://github.com/fabiosantoscode/terser#api-reference) for all supported options.
321
- Terser options can be passed directly to the `minifyJs` module:
322
- ```js
323
- htmlnano.process(html, {
324
- minifyJs: {
325
- output: { quote_style: 1 },
326
- },
327
- });
328
- ```
329
-
330
-
331
-
332
- #### Example
333
- Source:
334
- ```html
335
- <div>
336
- <script>
337
- /* comment */
338
- const foo = function () {
339
-
340
- };
341
- </script>
342
- </div>
343
- ```
344
-
345
- Minified:
346
- ```html
347
- <div>
348
- <script>const foo=function(){};</script>
349
- </div>
350
- ```
351
-
352
-
353
- ### minifyJson
354
- Minifies JSON inside `<script type="application/json"></script>`.
355
-
356
- #### Example
357
- Source:
358
- ```html
359
- <script type="application/json">
360
- {
361
- "user": "me"
362
- }
363
- </script>
364
- ```
365
-
366
- Minified:
367
- ```html
368
- <script type="application/json">{"user":"me"}</script>
369
- ```
370
-
371
-
372
- ### minifySvg
373
- Minifies SVG inside `<svg>` tags using [SVGO](https://github.com/svg/svgo/).
374
-
375
- #### Options
376
- See [the documentation of SVGO](https://github.com/svg/svgo/blob/master/README.md) for all supported options.
377
- SVGO options can be passed directly to the `minifySvg` module:
378
- ```js
379
- htmlnano.process(html, {
380
- minifySvg: {
381
- plugins: [
382
- {
383
- name: 'preset-default',
384
- params: {
385
- overrides: {
386
- builtinPluginName: {
387
- optionName: 'optionValue'
388
- },
389
- },
390
- },
391
- }
392
- ]
393
- }
394
- });
395
- ```
396
-
397
- #### Example
398
- Source:
399
- ```html
400
- <svg version="1.1" baseProfile="full" width="300" height="200" xmlns="http://www.w3.org/2000/svg">
401
- <rect width="100%" height="100%" fill="red" />
402
-
403
- <circle cx="150" cy="100" r="80" fill="green" />
404
-
405
- <text x="150" y="125" font-size="60" text-anchor="middle" fill="white">SVG</text>
406
- </svg>`
407
- ```
408
-
409
- Minified:
410
- ```html
411
- <svg baseProfile="full" width="300" height="200" xmlns="http://www.w3.org/2000/svg"><rect width="100%" height="100%" fill="red"/><circle cx="150" cy="100" r="80" fill="green"/><text x="150" y="125" font-size="60" text-anchor="middle" fill="#fff">SVG</text></svg>
412
- ```
413
-
414
- ### minifyConditionalComments
415
-
416
- Minify content inside conditional comments.
417
-
418
- #### Example
419
-
420
- Source:
421
-
422
- ```html
423
- <!--[if lte IE 7]>
424
- <style type="text/css">
425
- .title {
426
- color: red;
427
- }
428
- </style>
429
- <![endif]-->
430
- ```
431
-
432
- Minified:
433
-
434
- ```html
435
- <!--[if lte IE 7]><style>.title{color:red}</style><![endif]-->
436
- ```
437
-
438
- ### removeRedundantAttributes
439
- Removes redundant attributes from tags if they contain default values:
440
- - `method="get"` from `<form>`
441
- - `type="text"` from `<input>`
442
- - `type="submit"` from `<button>`
443
- - `language="javascript"` and `type="text/javascript"` from `<script>`
444
- - `charset` from `<script>` if it's an external script
445
- - `media="all"` from `<style>` and `<link>`
446
- - `type="text/css"` from `<link rel="stylesheet">`
447
-
448
- #### Options
449
- This module is disabled by default, change option to true to enable this module.
450
-
451
- #### Side effects
452
- This module could break your styles or JS if you use selectors with attributes:
453
- ```CSS
454
- form[method="get"] {
455
- color: red;
456
- }
457
- ```
458
-
459
- #### Example
460
- Source:
461
- ```html
462
- <form method="get">
463
- <input type="text">
464
- </form>
465
- ```
466
-
467
- Minified:
468
- ```html
469
- <form>
470
- <input>
471
- </form>
472
- ```
473
-
474
-
475
- ### collapseBooleanAttributes
476
- Collapses boolean attributes (like `disabled`) to the minimized form.
477
-
478
- #### Options
479
- If your document uses [AMP](https://www.ampproject.org/), set the `amphtml` flag
480
- to collapse additonal, AMP-specific boolean attributes:
481
- ```Json
482
- "collapseBooleanAttributes": {
483
- "amphtml": true
484
- }
485
- ```
486
-
487
- #### Side effects
488
- This module could break your styles or JS if you use selectors with attributes:
489
- ```CSS
490
- button[disabled="disabled"] {
491
- color: red;
492
- }
493
- ```
494
-
495
- #### Example
496
- Source:
497
- ```html
498
- <button disabled="disabled">click</button>
499
- <script defer=""></script>
500
- ```
501
-
502
- Minified:
503
- ```html
504
- <button disabled>click</button>
505
- <script defer></script>
506
- ```
507
-
508
-
509
- ### mergeStyles
510
- Merges multiple `<style>` with the same `media` and `type` into one tag.
511
- `<style scoped>...</style>` are skipped.
512
-
513
- #### Example
514
- Source:
515
- ```html
516
- <style>h1 { color: red }</style>
517
- <style media="print">div { color: blue }</style>
518
-
519
- <style type="text/css" media="print">a {}</style>
520
- <style>div { font-size: 20px }</style>
521
- ```
522
-
523
- Minified:
524
- ```html
525
- <style>h1 { color: red } div { font-size: 20px }</style>
526
- <style media="print">div { color: blue } a {}</style>
527
- ```
528
-
529
-
530
- ### mergeScripts
531
- Merge multiple `<script>` with the same attributes (`id, class, type, async, defer`) into one (last) tag.
532
-
533
- #### Side effects
534
- It could break your code if the tags with different attributes share the same variable scope.
535
- See the example below.
536
-
537
- #### Example
538
- Source:
539
- ```html
540
- <script>const foo = 'A:1';</script>
541
- <script class="test">foo = 'B:1';</script>
542
- <script type="text/javascript">foo = 'A:2';</script>
543
- <script defer>foo = 'C:1';</script>
544
- <script>foo = 'A:3';</script>
545
- <script defer="defer">foo = 'C:2';</script>
546
- <script class="test" type="text/javascript">foo = 'B:2';</script>
547
- ```
548
-
549
- Minified:
550
- ```html
551
- <script>const foo = 'A:1'; foo = 'A:2'; foo = 'A:3';</script>
552
- <script defer="defer">foo = 'C:1'; foo = 'C:2';</script>
553
- <script class="test" type="text/javascript">foo = 'B:1'; foo = 'B:2';</script>
554
- ```
555
-
556
-
557
- ### custom
558
- It's also possible to pass custom modules in the minifier.
559
- As a function:
560
- ```js
561
- const options = {
562
- custom: function (tree, options) {
563
- // Some minification
564
- return tree;
565
- }
566
- };
567
- ```
568
-
569
- Or as a list of functions:
570
- ```js
571
- const options = {
572
- custom: [
573
- function (tree, options) {
574
- // Some minification
575
- return tree;
576
- },
577
-
578
- function (tree, options) {
579
- // Some other minification
580
- return tree;
581
- }
582
- ]
583
- };
584
- ```
585
-
586
- `options` is an object with all options that were passed to the plugin.
587
-
588
- ### sortAttributesWithLists
589
- Sort values in list-like attributes (`class`, `rel`, `ping`).
590
-
591
- The module won't impact the plain-text size of the output. However it will improve the compression ratio of gzip/brotli used in HTTP compression.
592
-
593
- #### Options
594
-
595
- - `alphabetical`: Default option. Sort attribute values in alphabetical order.
596
- - `frequency`: Sort attribute values by frequency.
597
-
598
- #### Example
599
-
600
- **alphabetical**
601
-
602
- Source:
603
- ```html
604
- <div class="foo baz bar">click</div>
605
- ```
606
-
607
- Processed:
608
- ```html
609
- <div class="bar baz foo">click</div>
610
- ```
611
-
612
- **frequency**
613
-
614
- Source:
615
- ```html
616
- <div class="foo baz bar"></div><div class="bar foo"></div>
617
- ```
618
-
619
- Processed:
620
- ```html
621
- <div class="foo bar baz"></div><div class="foo bar"></div>
622
- ```
623
-
624
- ### sortAttributes
625
- Sort attributes inside elements.
626
-
627
- The module won't impact the plain-text size of the output. However it will improve the compression ratio of gzip/brotli used in HTTP compression.
628
-
629
- #### Options
630
-
631
- - `alphabetical`: Default option. Sort attributes in alphabetical order.
632
- - `frequency`: Sort attributes by frequency.
633
-
634
- #### Example
635
-
636
- **alphabetical**
637
-
638
- Source:
639
- ```html
640
- <input type="text" class="form-control" name="testInput" autofocus="" autocomplete="off" id="testId">
641
- ```
642
-
643
- Processed:
644
- ```html
645
- <input autocomplete="off" autofocus="" class="form-control" id="testId" name="testInput" type="text">
646
- ```
647
-
648
- **frequency**
649
-
650
- Source:
651
- ```html
652
- <input type="text" class="form-control" name="testInput" id="testId">
653
- <a id="testId" href="#" class="testClass"></a>
654
- <img width="20" src="../images/image.png" height="40" alt="image" class="cls" id="id2">
655
- ```
656
-
657
- Processed:
658
- ```html
659
- <input class="form-control" id="testId" type="text" name="testInput">
660
- <a class="testClass" id="testId" href="#"></a>
661
- <img class="cls" id="id2" width="20" src="../images/image.png" height="40" alt="image">
662
- ```
663
-
664
- ### minifyUrls
665
- Convert absolute URL to relative URL using [relateurl](https://www.npmjs.com/package/relateurl).
666
-
667
- #### Options
668
-
669
- The base URL to resolve against. Support `String` & `URL`.
670
-
671
- ```js
672
- htmlnano.process(html, {
673
- minifyUrls: 'https://example.com' // Valid configuration
674
- });
675
- ```
676
-
677
- ```js
678
- htmlnano.process(html, {
679
- minifyUrls: new URL('https://example.com') // Valid configuration
680
- });
681
- ```
682
-
683
- ```js
684
- htmlnano.process(html, {
685
- minifyUrls: false // The module will be disabled
686
- });
687
- ```
688
-
689
- ```js
690
- htmlnano.process(html, {
691
- minifyUrls: true // Invalid configuration, the module will be disabled
692
- });
693
- ```
694
-
695
- #### Example
696
-
697
- **Basic Usage**
698
-
699
- Configuration:
700
-
701
- ```js
702
- htmlnano.process(html, {
703
- minifyUrls: 'https://example.com'
704
- });
705
- ```
706
-
707
- Source:
708
-
709
- ```html
710
- <a href="https://example.com/foo/bar/baz">bar</a>
711
- ```
712
-
713
- Minified:
714
-
715
- ```html
716
- <a href="foo/bar/baz">bar</a>
717
- ```
718
-
719
- **With sub-directory**
720
-
721
- Configuration:
722
-
723
- ```js
724
- htmlnano.process(html, {
725
- minifyUrls: 'https://example.com/foo/baz/'
726
- });
727
- ```
728
-
729
- Source:
730
-
731
- ```html
732
- <a href="https://example.com/foo/bar">bar</a>
733
- ```
734
-
735
- Minified:
736
-
737
- ```html
738
- <a href="../bar">bar</a>
739
- ```
740
-
741
- ### removeOptionalTags
742
- Remove certain tags that can be omitted, see [HTML Standard - 13.1.2.4 Optional tags](https://html.spec.whatwg.org/multipage/syntax.html#optional-tags).
743
-
744
- #### Example
745
-
746
- Source:
747
-
748
- ```html
749
- <html><head><title>Title</title></head><body><p>Hi</p></body></html>
750
- ```
751
-
752
- Minified:
753
-
754
- ```html
755
- <title>Title</title><p>Hi</p>
756
- ```
757
-
758
- #### Notice
759
- Due to [the limitation of PostHTML](https://github.com/posthtml/htmlnano/issues/99), htmlnano can't remove only the start tag or the end tag of an element. Currently, htmlnano only supports removing the following optional tags, as htmlnano can remove their start tag and end tag at the same time:
760
-
761
- - `html`
762
- - `head`
763
- - `body`
764
- - `colgroup`
765
- - `tbody`
766
-
767
- ### normalizeAttributeValues
768
-
769
- Normalize casing of attribute values.
770
-
771
- The module won't impact the plain-text size of the output. However it will improve the compression ratio of gzip/brotli used in HTTP compression.
772
-
773
- #### Example
774
-
775
- Source:
776
-
777
- ```html
778
- <form method="GET"></form>
779
- ```
780
-
781
- Minified:
782
-
783
- ```html
784
- <form method="get"></form>
785
- ```