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