@ohos-ports/html-minifier-next 8.4.2-beta.0
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/LICENSE.txt +23 -0
- package/README.md +776 -0
- package/cli.js +1209 -0
- package/dist/types/htmlminifier.d.ts +556 -0
- package/dist/types/htmlminifier.d.ts.map +1 -0
- package/dist/types/htmlparser.d.ts +25 -0
- package/dist/types/htmlparser.d.ts.map +1 -0
- package/dist/types/lib/attributes.d.ts +155 -0
- package/dist/types/lib/attributes.d.ts.map +1 -0
- package/dist/types/lib/constants.d.ts +110 -0
- package/dist/types/lib/constants.d.ts.map +1 -0
- package/dist/types/lib/content.d.ts +51 -0
- package/dist/types/lib/content.d.ts.map +1 -0
- package/dist/types/lib/elements.d.ts +57 -0
- package/dist/types/lib/elements.d.ts.map +1 -0
- package/dist/types/lib/fragments.d.ts +46 -0
- package/dist/types/lib/fragments.d.ts.map +1 -0
- package/dist/types/lib/option-definitions.d.ts +33 -0
- package/dist/types/lib/option-definitions.d.ts.map +1 -0
- package/dist/types/lib/options.d.ts +120 -0
- package/dist/types/lib/options.d.ts.map +1 -0
- package/dist/types/lib/unused-css.d.ts +46 -0
- package/dist/types/lib/unused-css.d.ts.map +1 -0
- package/dist/types/lib/urls.d.ts +15 -0
- package/dist/types/lib/urls.d.ts.map +1 -0
- package/dist/types/lib/utils.d.ts +102 -0
- package/dist/types/lib/utils.d.ts.map +1 -0
- package/dist/types/lib/whitespace.d.ts +45 -0
- package/dist/types/lib/whitespace.d.ts.map +1 -0
- package/dist/types/presets.d.ts +49 -0
- package/dist/types/presets.d.ts.map +1 -0
- package/dist/types/tokenchain.d.ts +26 -0
- package/dist/types/tokenchain.d.ts.map +1 -0
- package/html-minifier-next.schema.json +306 -0
- package/package.json +100 -0
- package/src/htmlminifier.js +2294 -0
- package/src/htmlparser.js +1069 -0
- package/src/lib/attributes.js +928 -0
- package/src/lib/constants.js +285 -0
- package/src/lib/content.js +190 -0
- package/src/lib/elements.js +274 -0
- package/src/lib/file-pool.js +177 -0
- package/src/lib/fragments.js +274 -0
- package/src/lib/option-definitions.js +231 -0
- package/src/lib/options.js +730 -0
- package/src/lib/unused-css.js +379 -0
- package/src/lib/urls.js +155 -0
- package/src/lib/utils.js +861 -0
- package/src/lib/whitespace.js +321 -0
- package/src/presets.js +57 -0
- package/src/tokenchain.js +123 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom fragment matching
|
|
3
|
+
*
|
|
4
|
+
* `ignoreCustomFragments` patterns nearly always describe the same shape: a literal
|
|
5
|
+
* opening delimiter, an any-character or negated-class body, and a literal closing
|
|
6
|
+
* delimiter, as in `<%[\s\S]*?%>` or `\{\{[^}]*?\}\}`. Such a fragment can be found
|
|
7
|
+
* with `indexOf` in linear time, where running the pattern as a regex costs O(n²)
|
|
8
|
+
* on input that opens fragments it never closes—and can cost far more than that when
|
|
9
|
+
* the pattern itself backtracks. Patterns of other shapes keep running as regexes,
|
|
10
|
+
* one per pattern, so each keeps its own flags.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const RE_WHITESPACE = /\s/;
|
|
14
|
+
|
|
15
|
+
// Any-character and negated-class bodies; without the `s` flag, `.` is itself a
|
|
16
|
+
// negated class, excluding line terminators
|
|
17
|
+
const RE_DELIMITED = /^(.*?)(?:\[\\s\\S\]|\[\\S\\s\]|\[\^\]|(\.)|\[\^((?:\\[^]|[^\]\\])+)\])(?:([*+])|\{(\d+)(?:,(\d*))?\})\?(.*)$/;
|
|
18
|
+
|
|
19
|
+
// Flags that leave literal matching alone, so a pattern carrying them can still be
|
|
20
|
+
// scanned for; `i` in particular cannot, since case folding moves character indexes
|
|
21
|
+
const RE_LITERAL_FLAGS = /^[gds]*$/;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @typedef {{open: string, close: string, min: number, max: number, excluded: RegExp | null}} DelimitedFragment
|
|
25
|
+
* Literal delimiters around a body, found by scanning; `excluded` holds the
|
|
26
|
+
* characters a negated-class body cannot cross, null when the body spans every
|
|
27
|
+
* character
|
|
28
|
+
* @typedef {{search: RegExp, anchored: RegExp}} PatternFragment
|
|
29
|
+
* Everything else, found by running the pattern itself
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Read a regex source as a literal string, so it can be matched with `indexOf`
|
|
34
|
+
* @param {string} source
|
|
35
|
+
* @returns {string | null} Null when the source is more than literal characters
|
|
36
|
+
*/
|
|
37
|
+
function toLiteral(source) {
|
|
38
|
+
let literal = '';
|
|
39
|
+
|
|
40
|
+
for (let i = 0; i < source.length; i++) {
|
|
41
|
+
const char = source[i] ?? '';
|
|
42
|
+
if (char === '\\') {
|
|
43
|
+
const escaped = source[++i];
|
|
44
|
+
// A trailing backslash is half an escape the body token was split out of,
|
|
45
|
+
// as in `<%\.*?%>`, where the `.` is literal and not a body
|
|
46
|
+
if (escaped === undefined) return null;
|
|
47
|
+
// `\n` and friends are literal characters, `\s` and `\1` are not
|
|
48
|
+
if (escaped === 'n') literal += '\n';
|
|
49
|
+
else if (escaped === 't') literal += '\t';
|
|
50
|
+
else if (escaped === 'r') literal += '\r';
|
|
51
|
+
else if (escaped === 'f') literal += '\f';
|
|
52
|
+
else if (escaped === 'v') literal += '\v';
|
|
53
|
+
else if (/[A-Za-z0-9]/.test(escaped)) return null;
|
|
54
|
+
else literal += escaped;
|
|
55
|
+
} else if ('.*+?()[]{}|^$'.includes(char)) {
|
|
56
|
+
return null;
|
|
57
|
+
} else {
|
|
58
|
+
literal += char;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return literal;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Describe a fragment pattern as literal delimiters around an any-character body
|
|
67
|
+
* @param {RegExp} pattern
|
|
68
|
+
* @returns {DelimitedFragment | null} Null when the pattern has another shape, which
|
|
69
|
+
* the caller answers by running it as a regex
|
|
70
|
+
*/
|
|
71
|
+
function toDelimitedFragment(pattern) {
|
|
72
|
+
if (!RE_LITERAL_FLAGS.test(pattern.flags)) return null;
|
|
73
|
+
|
|
74
|
+
const match = RE_DELIMITED.exec(pattern.source);
|
|
75
|
+
if (!match) return null;
|
|
76
|
+
|
|
77
|
+
const [, rawOpen, dot, negated, simple, exact, upper, rawClose] = match;
|
|
78
|
+
const open = toLiteral(rawOpen ?? '');
|
|
79
|
+
const close = toLiteral(rawClose ?? '');
|
|
80
|
+
// Both delimiters have to be there: without them a match has no boundary to scan to
|
|
81
|
+
if (!open || !close) return null;
|
|
82
|
+
|
|
83
|
+
// The class content doubles as the search for characters the body cannot cross;
|
|
84
|
+
// a `.` body spans every character under the `s` flag, and excludes line
|
|
85
|
+
// terminators without it
|
|
86
|
+
const inner = dot ? (pattern.flags.includes('s') ? null : '\\n\\r\\u2028\\u2029') : negated ?? null;
|
|
87
|
+
|
|
88
|
+
const min = simple ? (simple === '+' ? 1 : 0) : Number(exact);
|
|
89
|
+
const max = simple || upper === '' ? Infinity : Number(upper ?? exact);
|
|
90
|
+
|
|
91
|
+
return { open, close, min, max, excluded: inner === null ? null : new RegExp('[' + inner + ']', 'g') };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Prepare a fragment pattern for matching, by scanning where the shape allows it
|
|
96
|
+
* @param {RegExp} pattern
|
|
97
|
+
* @returns {DelimitedFragment | PatternFragment}
|
|
98
|
+
*/
|
|
99
|
+
function toFragment(pattern) {
|
|
100
|
+
const delimited = toDelimitedFragment(pattern);
|
|
101
|
+
if (delimited) return delimited;
|
|
102
|
+
|
|
103
|
+
// `g` and `y` are ours to set, the rest belong to the pattern
|
|
104
|
+
const flags = pattern.flags.replace(/[gy]/g, '');
|
|
105
|
+
return { search: new RegExp(pattern.source, flags + 'g'), anchored: new RegExp(pattern.source, flags + 'y') };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Replace runs of custom fragments, and the whitespace padding them
|
|
110
|
+
* @param {string} value - Document to scan
|
|
111
|
+
* @param {(DelimitedFragment | PatternFragment)[]} fragments - In the order the patterns
|
|
112
|
+
* were given, since the earliest match wins and ties go to the pattern listed first
|
|
113
|
+
* @param {(match: string) => string} replacer - Called with each match, as `replace` would
|
|
114
|
+
* @returns {string}
|
|
115
|
+
*/
|
|
116
|
+
function replaceCustomFragments(value, fragments, replacer) {
|
|
117
|
+
// Where each fragment's next match may start, its next closing delimiter may be
|
|
118
|
+
// found, and its next excluded character sits; all only ever move forward, which
|
|
119
|
+
// is what keeps the whole scan linear
|
|
120
|
+
const found = fragments.map(() => /** @type {{start: number, end: number} | null} */ (null));
|
|
121
|
+
const closesAt = fragments.map(() => -1);
|
|
122
|
+
const excludedAt = fragments.map(() => -1);
|
|
123
|
+
const exhausted = fragments.map(() => false);
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Whether a body region holds a character its class excludes
|
|
127
|
+
* @param {DelimitedFragment} fragment
|
|
128
|
+
* @param {number} index - Which fragment, for the forward-only bookkeeping
|
|
129
|
+
* @param {number} bodyStart
|
|
130
|
+
* @param {number} close
|
|
131
|
+
* @returns {boolean}
|
|
132
|
+
*/
|
|
133
|
+
const bodyBlocked = (fragment, index, bodyStart, close) => {
|
|
134
|
+
if (!fragment.excluded) return false;
|
|
135
|
+
if (/** @type {number} */ (excludedAt[index]) < bodyStart) {
|
|
136
|
+
fragment.excluded.lastIndex = bodyStart;
|
|
137
|
+
const blocked = fragment.excluded.exec(value);
|
|
138
|
+
excludedAt[index] = blocked ? blocked.index : Infinity;
|
|
139
|
+
}
|
|
140
|
+
return /** @type {number} */ (excludedAt[index]) < close;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Earliest match of one delimited fragment at or after `from`
|
|
145
|
+
* @param {DelimitedFragment} fragment
|
|
146
|
+
* @param {number} index - Which fragment, for the forward-only bookkeeping
|
|
147
|
+
* @param {number} from
|
|
148
|
+
* @param {boolean} anchored - Whether the match has to start exactly at `from`
|
|
149
|
+
* @returns {{start: number, end: number} | null}
|
|
150
|
+
*/
|
|
151
|
+
const scan = (fragment, index, from, anchored) => {
|
|
152
|
+
let openFrom = from;
|
|
153
|
+
|
|
154
|
+
for (;;) {
|
|
155
|
+
const open = anchored
|
|
156
|
+
? (value.startsWith(fragment.open, from) ? from : -1)
|
|
157
|
+
: value.indexOf(fragment.open, openFrom);
|
|
158
|
+
if (open === -1) {
|
|
159
|
+
if (!anchored) exhausted[index] = true;
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const bodyStart = open + fragment.open.length;
|
|
164
|
+
if (/** @type {number} */ (closesAt[index]) < bodyStart + fragment.min) {
|
|
165
|
+
closesAt[index] = value.indexOf(fragment.close, bodyStart + fragment.min);
|
|
166
|
+
}
|
|
167
|
+
const close = /** @type {number} */ (closesAt[index]);
|
|
168
|
+
if (close === -1) {
|
|
169
|
+
exhausted[index] = true;
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (close - bodyStart <= fragment.max && !bodyBlocked(fragment, index, bodyStart, close)) {
|
|
174
|
+
return { start: open, end: close + fragment.close.length };
|
|
175
|
+
}
|
|
176
|
+
// The body is longer than the pattern allows, or holds a character its class
|
|
177
|
+
// excludes, so the match has to start later
|
|
178
|
+
if (anchored) return null;
|
|
179
|
+
openFrom = open + 1;
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Earliest match of one regex fragment at or after `from`
|
|
185
|
+
* @param {PatternFragment} fragment
|
|
186
|
+
* @param {number} from
|
|
187
|
+
* @param {boolean} anchored
|
|
188
|
+
* @returns {{start: number, end: number} | null}
|
|
189
|
+
*/
|
|
190
|
+
const run = (fragment, from, anchored) => {
|
|
191
|
+
const pattern = anchored ? fragment.anchored : fragment.search;
|
|
192
|
+
pattern.lastIndex = from;
|
|
193
|
+
|
|
194
|
+
for (;;) {
|
|
195
|
+
const match = pattern.exec(value);
|
|
196
|
+
if (!match) return null;
|
|
197
|
+
// A pattern that matches nothing would leave the run in place forever
|
|
198
|
+
if (match[0].length > 0) return { start: match.index, end: match.index + match[0].length };
|
|
199
|
+
if (anchored) return null;
|
|
200
|
+
pattern.lastIndex = match.index + 1;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* @param {number} from
|
|
206
|
+
* @param {boolean} anchored
|
|
207
|
+
* @returns {{start: number, end: number} | null}
|
|
208
|
+
*/
|
|
209
|
+
const find = (from, anchored) => {
|
|
210
|
+
/** @type {{start: number, end: number} | null} */
|
|
211
|
+
let earliest = null;
|
|
212
|
+
|
|
213
|
+
for (let i = 0; i < fragments.length; i++) {
|
|
214
|
+
if (exhausted[i]) continue;
|
|
215
|
+
const fragment = /** @type {DelimitedFragment | PatternFragment} */ (fragments[i]);
|
|
216
|
+
|
|
217
|
+
/** @type {{start: number, end: number} | null} */
|
|
218
|
+
let match;
|
|
219
|
+
if (anchored) {
|
|
220
|
+
match = 'open' in fragment ? scan(fragment, i, from, true) : run(fragment, from, true);
|
|
221
|
+
} else {
|
|
222
|
+
// Matches only ever move forward, so the last one found still stands
|
|
223
|
+
const previous = found[i];
|
|
224
|
+
match = previous && previous.start >= from
|
|
225
|
+
? previous
|
|
226
|
+
: ('open' in fragment ? scan(fragment, i, from, false) : run(fragment, from, false));
|
|
227
|
+
found[i] = match;
|
|
228
|
+
// Nothing ahead now means nothing ahead later, either
|
|
229
|
+
if (!match) exhausted[i] = true;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Ties go to the fragment listed first, the way alternation would resolve them
|
|
233
|
+
if (match && (!earliest || match.start < earliest.start)) earliest = match;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return earliest;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
let out = '';
|
|
240
|
+
let copied = 0;
|
|
241
|
+
let search = 0;
|
|
242
|
+
|
|
243
|
+
while (search <= value.length) {
|
|
244
|
+
const first = find(search, false);
|
|
245
|
+
if (!first) break;
|
|
246
|
+
|
|
247
|
+
// Fragments running straight into each other are one match
|
|
248
|
+
let end = first.end;
|
|
249
|
+
for (;;) {
|
|
250
|
+
const next = find(end, true);
|
|
251
|
+
if (!next) break;
|
|
252
|
+
end = next.end;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// …as is the whitespace on either side, back to where the last match left off
|
|
256
|
+
let start = first.start;
|
|
257
|
+
while (start > copied && RE_WHITESPACE.test(value[start - 1] ?? '')) start--;
|
|
258
|
+
while (end < value.length && RE_WHITESPACE.test(value[end] ?? '')) end++;
|
|
259
|
+
|
|
260
|
+
out += value.slice(copied, start) + replacer(value.slice(start, end));
|
|
261
|
+
copied = end;
|
|
262
|
+
search = end;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return copied === 0 ? value : out + value.slice(copied);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Exports
|
|
269
|
+
|
|
270
|
+
export {
|
|
271
|
+
toDelimitedFragment,
|
|
272
|
+
toFragment,
|
|
273
|
+
replaceCustomFragments
|
|
274
|
+
};
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single source of truth for minifier option names, descriptions, types, and shared defaults
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {object} OptionDefinition
|
|
7
|
+
* @property {string} description Help text, phrased for the option’s primary CLI form
|
|
8
|
+
* @property {string} [descriptionAffirmative] Help text for what enabling the option does, where `description` describes the negated form
|
|
9
|
+
* @property {string} type Key into the parser and JSON Schema type maps in cli.js and scripts/build-schema.js
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** @type {Record<string, OptionDefinition>} */
|
|
13
|
+
const optionDefinitions = {
|
|
14
|
+
cacheCSS: {
|
|
15
|
+
description: 'Set CSS minification cache size (number of entries, default: 500)',
|
|
16
|
+
type: 'int'
|
|
17
|
+
},
|
|
18
|
+
cacheJS: {
|
|
19
|
+
description: 'Set JavaScript minification cache size (number of entries, default: 500)',
|
|
20
|
+
type: 'int'
|
|
21
|
+
},
|
|
22
|
+
cacheSVG: {
|
|
23
|
+
description: 'Set SVG minification cache size (number of entries, default: 500)',
|
|
24
|
+
type: 'int'
|
|
25
|
+
},
|
|
26
|
+
caseSensitive: {
|
|
27
|
+
description: 'Treat attributes in case-sensitive manner (useful for custom HTML elements)',
|
|
28
|
+
type: 'boolean'
|
|
29
|
+
},
|
|
30
|
+
collapseAttributeWhitespace: {
|
|
31
|
+
description: 'Trim and collapse whitespace characters within attribute values',
|
|
32
|
+
type: 'boolean'
|
|
33
|
+
},
|
|
34
|
+
collapseBooleanAttributes: {
|
|
35
|
+
description: 'Omit attribute values from boolean attributes',
|
|
36
|
+
type: 'boolean'
|
|
37
|
+
},
|
|
38
|
+
collapseInlineTagWhitespace: {
|
|
39
|
+
description: 'Collapse whitespace more aggressively between inline elements—use with `--collapse-whitespace`',
|
|
40
|
+
type: 'boolean'
|
|
41
|
+
},
|
|
42
|
+
collapseWhitespace: {
|
|
43
|
+
description: 'Collapse whitespace that contributes to text nodes in a document tree',
|
|
44
|
+
type: 'boolean'
|
|
45
|
+
},
|
|
46
|
+
conservativeCollapse: {
|
|
47
|
+
description: 'Always collapse to one space (never remove it entirely)—use with `--collapse-whitespace`',
|
|
48
|
+
type: 'boolean'
|
|
49
|
+
},
|
|
50
|
+
continueOnMinifyError: {
|
|
51
|
+
description: 'Abort on minification errors',
|
|
52
|
+
descriptionAffirmative: 'Continue on minification errors',
|
|
53
|
+
type: 'invertedBoolean'
|
|
54
|
+
},
|
|
55
|
+
continueOnParseError: {
|
|
56
|
+
description: 'Handle parse errors instead of aborting',
|
|
57
|
+
type: 'boolean'
|
|
58
|
+
},
|
|
59
|
+
customAttrAssign: {
|
|
60
|
+
description: 'Array of regexes that allow to support custom attribute assign expressions (e.g., `<div flex?="{{mode != cover}}"></div>`)',
|
|
61
|
+
type: 'regexpArray'
|
|
62
|
+
},
|
|
63
|
+
customAttrCollapse: {
|
|
64
|
+
description: 'Regex that specifies custom attribute to strip newlines from (e.g., `/ng-class/`)',
|
|
65
|
+
type: 'regexp'
|
|
66
|
+
},
|
|
67
|
+
customAttrSurround: {
|
|
68
|
+
description: 'Array of regexes that allow to support custom attribute surround expressions (e.g., `<input {{#if value}}checked="checked"{{/if}}>`)',
|
|
69
|
+
type: 'regexpArray'
|
|
70
|
+
},
|
|
71
|
+
customEventAttributes: {
|
|
72
|
+
description: 'Array of regexes that allow to support custom event attributes (e.g., `ng-click`)—use with `--minify-js`',
|
|
73
|
+
type: 'regexpArray'
|
|
74
|
+
},
|
|
75
|
+
decodeEntities: {
|
|
76
|
+
description: 'Use direct Unicode characters whenever possible',
|
|
77
|
+
type: 'boolean'
|
|
78
|
+
},
|
|
79
|
+
ignoreCustomComments: {
|
|
80
|
+
description: 'Array of regexes that allow to ignore matching comments',
|
|
81
|
+
type: 'regexpArray'
|
|
82
|
+
},
|
|
83
|
+
ignoreCustomFragments: {
|
|
84
|
+
description: 'Array of regexes that allow to ignore certain fragments, when matched (e.g., `<?php \u2026 ?>`, `{{ \u2026 }}`)',
|
|
85
|
+
type: 'regexpArray'
|
|
86
|
+
},
|
|
87
|
+
includeAutoGeneratedTags: {
|
|
88
|
+
description: 'Insert elements generated by HTML parser',
|
|
89
|
+
type: 'boolean'
|
|
90
|
+
},
|
|
91
|
+
inlineCustomElements: {
|
|
92
|
+
description: 'Array of names of custom elements which are inline, for whitespace handling—use with `--collapse-whitespace`',
|
|
93
|
+
type: 'jsonArray'
|
|
94
|
+
},
|
|
95
|
+
keepClosingSlash: {
|
|
96
|
+
description: 'Keep the trailing slash on void elements and other start tags that carry one, and read it as closing the element',
|
|
97
|
+
type: 'boolean'
|
|
98
|
+
},
|
|
99
|
+
maxInputLength: {
|
|
100
|
+
description: 'Maximum input length to prevent ReDoS attacks',
|
|
101
|
+
type: 'int'
|
|
102
|
+
},
|
|
103
|
+
maxLineLength: {
|
|
104
|
+
description: 'Specify a maximum line length; compressed output will be split by newlines at valid HTML split-points',
|
|
105
|
+
type: 'int'
|
|
106
|
+
},
|
|
107
|
+
mergeScripts: {
|
|
108
|
+
description: 'Merge consecutive inline `script` elements into one',
|
|
109
|
+
type: 'boolean'
|
|
110
|
+
},
|
|
111
|
+
minifyCSS: {
|
|
112
|
+
description: 'Minify CSS in `style` elements and attributes (uses Lightning CSS)',
|
|
113
|
+
type: 'jsonObject'
|
|
114
|
+
},
|
|
115
|
+
minifyJS: {
|
|
116
|
+
description: 'Minify JavaScript in `script` elements and event attributes (uses Terser or SWC; pass `{"engine": "swc"}` for SWC)',
|
|
117
|
+
type: 'jsonObject'
|
|
118
|
+
},
|
|
119
|
+
minifySVG: {
|
|
120
|
+
description: 'Minify SVG elements (uses SVGO)',
|
|
121
|
+
type: 'jsonObject'
|
|
122
|
+
},
|
|
123
|
+
minifyURLs: {
|
|
124
|
+
description: 'Minify URLs in various attributes',
|
|
125
|
+
type: 'json'
|
|
126
|
+
},
|
|
127
|
+
noNewlinesBeforeTagClose: {
|
|
128
|
+
description: 'Never add a newline before a tag that closes an element—use with `--max-line-length`',
|
|
129
|
+
type: 'boolean'
|
|
130
|
+
},
|
|
131
|
+
partialMarkup: {
|
|
132
|
+
description: 'Treat input as a partial HTML fragment, preserving stray end tags and unclosed tags',
|
|
133
|
+
type: 'boolean'
|
|
134
|
+
},
|
|
135
|
+
preserveLineBreaks: {
|
|
136
|
+
description: 'Always collapse to one line break (never remove it entirely) when whitespace between tags includes a line break—use with `--collapse-whitespace`',
|
|
137
|
+
type: 'boolean'
|
|
138
|
+
},
|
|
139
|
+
preventAttributesEscaping: {
|
|
140
|
+
description: 'Prevents the escaping of the values of attributes',
|
|
141
|
+
type: 'boolean'
|
|
142
|
+
},
|
|
143
|
+
processScripts: {
|
|
144
|
+
description: 'Array of strings corresponding to types of `script` elements to process through minifier (e.g., `text/ng-template`, `text/x-handlebars-template`, etc.)',
|
|
145
|
+
type: 'jsonArray'
|
|
146
|
+
},
|
|
147
|
+
quoteCharacter: {
|
|
148
|
+
description: 'Type of quote to use for attribute values (`\'` or `"`)',
|
|
149
|
+
type: 'string'
|
|
150
|
+
},
|
|
151
|
+
removeAttributeQuotes: {
|
|
152
|
+
description: 'Remove quotes around attributes when possible',
|
|
153
|
+
type: 'boolean'
|
|
154
|
+
},
|
|
155
|
+
removeComments: {
|
|
156
|
+
description: 'Strip HTML comments',
|
|
157
|
+
type: 'boolean'
|
|
158
|
+
},
|
|
159
|
+
removeDefaultTypeAttributes: {
|
|
160
|
+
description: 'Remove default `type` attributes from `style`/`link` (e.g., `type="text/css"`) and `script` (e.g., `type="text/javascript"`) elements; other `type` attribute values are left intact',
|
|
161
|
+
type: 'boolean'
|
|
162
|
+
},
|
|
163
|
+
removeEmptyAttributes: {
|
|
164
|
+
description: 'Remove all attributes with whitespace-only values',
|
|
165
|
+
type: 'boolean'
|
|
166
|
+
},
|
|
167
|
+
removeEmptyElements: {
|
|
168
|
+
description: 'Remove all elements with empty contents',
|
|
169
|
+
type: 'boolean'
|
|
170
|
+
},
|
|
171
|
+
removeEmptyElementsExcept: {
|
|
172
|
+
description: 'Array of elements to preserve (e.g., `td`, `<span aria-hidden="true">`)—use with `--remove-empty-elements`',
|
|
173
|
+
type: 'jsonArray'
|
|
174
|
+
},
|
|
175
|
+
removeOptionalTags: {
|
|
176
|
+
description: 'Remove optional tags',
|
|
177
|
+
type: 'boolean'
|
|
178
|
+
},
|
|
179
|
+
removeRedundantAttributes: {
|
|
180
|
+
description: 'Remove attributes when value matches default',
|
|
181
|
+
type: 'boolean'
|
|
182
|
+
},
|
|
183
|
+
removeTagWhitespace: {
|
|
184
|
+
description: 'Remove space between attributes whenever possible; note that this will result in invalid HTML',
|
|
185
|
+
type: 'boolean'
|
|
186
|
+
},
|
|
187
|
+
removeUnusedCSS: {
|
|
188
|
+
description: 'Remove rules from `style` elements whose class or ID selectors the document never references—use with `--minify-css`; note that class names only applied by external scripts cannot be detected—use `{"safelist": […]}` for those',
|
|
189
|
+
type: 'jsonObject'
|
|
190
|
+
},
|
|
191
|
+
sortAttributes: {
|
|
192
|
+
description: 'Sort attributes by frequency',
|
|
193
|
+
type: 'boolean'
|
|
194
|
+
},
|
|
195
|
+
sortClassNames: {
|
|
196
|
+
description: 'Sort style classes by frequency',
|
|
197
|
+
type: 'boolean'
|
|
198
|
+
},
|
|
199
|
+
trimCustomFragments: {
|
|
200
|
+
description: 'Trim whitespace around custom fragments (`--ignore-custom-fragments`)—use with `--collapse-whitespace`',
|
|
201
|
+
type: 'boolean'
|
|
202
|
+
},
|
|
203
|
+
strictCustomFragments: {
|
|
204
|
+
description: 'Reject `ignoreCustomFragments` patterns that risk catastrophic backtracking (rather than warning about them)',
|
|
205
|
+
type: 'boolean'
|
|
206
|
+
},
|
|
207
|
+
useShortDoctype: {
|
|
208
|
+
description: 'Replaces the doctype with the short HTML doctype',
|
|
209
|
+
type: 'boolean'
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const optionDefaults = {
|
|
214
|
+
continueOnMinifyError: true,
|
|
215
|
+
ignoreCustomComments: [
|
|
216
|
+
/^!/,
|
|
217
|
+
/^\s*#/
|
|
218
|
+
],
|
|
219
|
+
ignoreCustomFragments: [
|
|
220
|
+
/<%[\s\S]*?%>/,
|
|
221
|
+
/<\?[\s\S]*?\?>/
|
|
222
|
+
],
|
|
223
|
+
includeAutoGeneratedTags: false
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
// Exports
|
|
227
|
+
|
|
228
|
+
export {
|
|
229
|
+
optionDefinitions,
|
|
230
|
+
optionDefaults
|
|
231
|
+
};
|