html-minifier-next 7.2.0 → 7.4.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/README.md +49 -24
- package/cli.js +40 -1
- package/dist/types/htmlminifier.d.ts +77 -20
- package/dist/types/htmlminifier.d.ts.map +1 -1
- package/dist/types/htmlparser.d.ts +11 -11
- package/dist/types/htmlparser.d.ts.map +1 -1
- package/dist/types/lib/attributes.d.ts +36 -38
- package/dist/types/lib/attributes.d.ts.map +1 -1
- package/dist/types/lib/constants.d.ts +97 -100
- package/dist/types/lib/constants.d.ts.map +1 -1
- package/dist/types/lib/content.d.ts +7 -6
- package/dist/types/lib/content.d.ts.map +1 -1
- package/dist/types/lib/elements.d.ts +13 -18
- package/dist/types/lib/elements.d.ts.map +1 -1
- package/dist/types/lib/option-definitions.d.ts +202 -299
- package/dist/types/lib/option-definitions.d.ts.map +1 -1
- package/dist/types/lib/options.d.ts +7 -14
- package/dist/types/lib/options.d.ts.map +1 -1
- package/dist/types/lib/urls.d.ts +10 -2
- package/dist/types/lib/urls.d.ts.map +1 -1
- package/dist/types/lib/utils.d.ts +30 -10
- package/dist/types/lib/utils.d.ts.map +1 -1
- package/dist/types/lib/whitespace.d.ts +7 -6
- package/dist/types/lib/whitespace.d.ts.map +1 -1
- package/dist/types/presets.d.ts +39 -37
- package/dist/types/presets.d.ts.map +1 -1
- package/dist/types/tokenchain.d.ts +13 -11
- package/dist/types/tokenchain.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/htmlminifier.js +34 -1
- package/src/lib/options.js +43 -31
- package/src/lib/urls.js +1 -1
- package/src/lib/utils.js +14 -0
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ The project was based on [HTML Minifier Terser (HMT)](https://github.com/terser/
|
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
11
|
-
HTML Minifier Next is ESM-only and requires Node.js ≥22.
|
|
11
|
+
HTML Minifier Next is ESM-only and requires Node.js ≥22.13.
|
|
12
12
|
|
|
13
13
|
For use as a command-line app, use npx:
|
|
14
14
|
|
|
@@ -40,13 +40,13 @@ Use `npx html-minifier-next --help` to check all available options:
|
|
|
40
40
|
| `--output <file>`, `-o <file>` | Specify output file (reads from `--input` file argument or STDIN; outputs to STDOUT if not specified) | File to file: `npx html-minifier-next input.html -o output.html`<br>File to file (explicit): `npx html-minifier-next -i input.html -o output.html`<br>Pipe to file: `cat input.html \| npx html-minifier-next -o output.html`<br>File to STDOUT: `npx html-minifier-next input.html` |
|
|
41
41
|
| `--file-ext <extensions>`, `-f <extensions>` | Specify file extension(s) to process (comma-separated, overrides config file setting); defaults to `html,htm,shtml,shtm`; use `*` for all files | `--file-ext=html,php`, `--file-ext='*'` |
|
|
42
42
|
| `--preset <name>`, `-p <name>` | Use a preset configuration (conservative or comprehensive) | `--preset=conservative` |
|
|
43
|
-
| `--config-file <file>`, `-c <file>` | Use a configuration file | `--config-file=
|
|
43
|
+
| `--config-file <file>`, `-c <file>` | Use a configuration file (defaults to `html-minifier-next.config.json` in the working directory, if present) | `--config-file=path/to/config.json` |
|
|
44
44
|
| `--verbose`, `-v` | Show detailed processing information (active options, file statistics) | `npx html-minifier-next --input-dir=src --output-dir=dist --verbose --collapse-whitespace` |
|
|
45
45
|
| `--dry`, `-d` | Dry run: Process and report statistics without writing output | `npx html-minifier-next input.html --dry --collapse-whitespace` |
|
|
46
46
|
|
|
47
47
|
### Configuration file
|
|
48
48
|
|
|
49
|
-
You can use a configuration file to specify options. The file can be either in JSON format or a JavaScript module that exports the configuration object:
|
|
49
|
+
You can use a configuration file to specify options. If an `html-minifier-next.config.json` file is present in the current working directory—only there; subfolders (including `--input-dir`) and parent folders are not searched—the CLI picks it up automatically, with a note on STDERR confirming this. An explicit `--config-file` takes precedence. (The standalone `--zero` mode is deliberately config-free and ignores default config files.) The file can be either in JSON format or a JavaScript module that exports the configuration object:
|
|
50
50
|
|
|
51
51
|
**JSON configuration example:**
|
|
52
52
|
|
|
@@ -73,7 +73,7 @@ For editor support (validation, autocomplete, and inline documentation) in JSON
|
|
|
73
73
|
|
|
74
74
|
**JavaScript module configuration example** (requires `"type": "module"` in the project’s package.json, or use a .mjs extension):
|
|
75
75
|
|
|
76
|
-
```
|
|
76
|
+
```js
|
|
77
77
|
export default {
|
|
78
78
|
collapseWhitespace: true,
|
|
79
79
|
removeComments: true,
|
|
@@ -84,7 +84,7 @@ export default {
|
|
|
84
84
|
|
|
85
85
|
### Node.js
|
|
86
86
|
|
|
87
|
-
```
|
|
87
|
+
```js
|
|
88
88
|
import { minify } from 'html-minifier-next';
|
|
89
89
|
|
|
90
90
|
const result = await minify('<p title="example" id="moo">foo</p>', {
|
|
@@ -112,8 +112,8 @@ To review the specific options set, [presets.js](https://github.com/j9t/html-min
|
|
|
112
112
|
npx html-minifier-next --preset conservative input.html
|
|
113
113
|
|
|
114
114
|
# Via config file
|
|
115
|
-
npx html-minifier-next --config-file=
|
|
116
|
-
# where
|
|
115
|
+
npx html-minifier-next --config-file=path/to/config.json input.html
|
|
116
|
+
# where config.json contains `{ "preset": "conservative" }`
|
|
117
117
|
|
|
118
118
|
# Override preset options
|
|
119
119
|
npx html-minifier-next --preset conservative --remove-empty-attributes input.html
|
|
@@ -198,7 +198,7 @@ When `minifyCSS` is set to `true`, HTML Minifier Next uses [Lightning CSS](https
|
|
|
198
198
|
|
|
199
199
|
You can pass Lightning CSS configuration options by providing an object:
|
|
200
200
|
|
|
201
|
-
```
|
|
201
|
+
```js
|
|
202
202
|
const result = await minify(html, {
|
|
203
203
|
minifyCSS: {
|
|
204
204
|
targets: {
|
|
@@ -221,7 +221,7 @@ Available Lightning CSS options when passed as an object:
|
|
|
221
221
|
|
|
222
222
|
For advanced usage, you can also pass a function:
|
|
223
223
|
|
|
224
|
-
```
|
|
224
|
+
```js
|
|
225
225
|
const result = await minify(html, {
|
|
226
226
|
minifyCSS: function(text, type) {
|
|
227
227
|
// `text`: CSS string to minify
|
|
@@ -237,7 +237,7 @@ When `minifyJS` is set to `true`, HTML Minifier Next uses [Terser](https://terse
|
|
|
237
237
|
|
|
238
238
|
You can choose between different JS minifiers using the `engine` field:
|
|
239
239
|
|
|
240
|
-
```
|
|
240
|
+
```js
|
|
241
241
|
const result = await minify(html, {
|
|
242
242
|
minifyJS: {
|
|
243
243
|
engine: 'swc', // Use SWC for faster minification
|
|
@@ -261,7 +261,7 @@ npm i -D @swc/core
|
|
|
261
261
|
|
|
262
262
|
You can pass engine-specific configuration options:
|
|
263
263
|
|
|
264
|
-
```
|
|
264
|
+
```js
|
|
265
265
|
// Using Terser with custom options
|
|
266
266
|
const result = await minify(html, {
|
|
267
267
|
minifyJS: {
|
|
@@ -281,7 +281,7 @@ const result = await minify(html, {
|
|
|
281
281
|
|
|
282
282
|
For advanced usage, you can also pass a function:
|
|
283
283
|
|
|
284
|
-
```
|
|
284
|
+
```js
|
|
285
285
|
const result = await minify(html, {
|
|
286
286
|
minifyJS: function(text, inline) {
|
|
287
287
|
// `text`: JavaScript string to minify
|
|
@@ -295,7 +295,7 @@ const result = await minify(html, {
|
|
|
295
295
|
|
|
296
296
|
When `minifySVG` is set to `true`, HTML Minifier Next uses [SVGO](https://svgo.dev/) to optimize inline SVG elements. Complete `<svg>` subtrees are extracted and processed as a block, enabling deep structural optimization:
|
|
297
297
|
|
|
298
|
-
```
|
|
298
|
+
```js
|
|
299
299
|
const result = await minify(html, {
|
|
300
300
|
minifySVG: true // Enable with SVGO defaults
|
|
301
301
|
});
|
|
@@ -303,7 +303,7 @@ const result = await minify(html, {
|
|
|
303
303
|
|
|
304
304
|
You can pass custom SVGO options:
|
|
305
305
|
|
|
306
|
-
```
|
|
306
|
+
```js
|
|
307
307
|
const result = await minify(html, {
|
|
308
308
|
minifySVG: {
|
|
309
309
|
plugins: [{
|
|
@@ -328,7 +328,7 @@ const result = await minify(html, {
|
|
|
328
328
|
|
|
329
329
|
HTML Minifier Next uses in-memory caches to improve performance when processing multiple files or repeated content. The cache sizes can be configured for optimal performance based on your use case:
|
|
330
330
|
|
|
331
|
-
```
|
|
331
|
+
```js
|
|
332
332
|
const result = await minify(html, {
|
|
333
333
|
minifyCSS: true,
|
|
334
334
|
minifyJS: true,
|
|
@@ -379,9 +379,34 @@ npx html-minifier-next --minify-css --minify-js --minify-svg input.html
|
|
|
379
379
|
|
|
380
380
|
* Cache locking: Caches are created on the first `minify()` call and persist for the process lifetime. Cache sizes are locked after first initialization—subsequent calls reuse the same caches even if different `cacheCSS`, `cacheJS`, or `cacheSVG` options are provided. The first call’s options determine the cache sizes.
|
|
381
381
|
* Zero values: Explicit `0` values are coerced to `1` (minimum functional cache size) to avoid immediate eviction. To keep the cache footprint as small as possible, use a small number like `10` or `50` instead of `0`.
|
|
382
|
+
* Entry size cap: Individual CSS, JavaScript, or SVG blocks larger than 1 MB are minified normally but not stored in the cache—this bounds worst-case cache memory without affecting realistically sized inline content. (This cutoff is fixed and not configurable.)
|
|
382
383
|
|
|
383
384
|
The caches persist across multiple `minify()` calls, making them particularly effective when processing many files in a batch operation.
|
|
384
385
|
|
|
386
|
+
**Inspecting cache effectiveness:**
|
|
387
|
+
|
|
388
|
+
Use `getCacheStats()` to see hit/miss counts and current occupancy for each cache:
|
|
389
|
+
|
|
390
|
+
```js
|
|
391
|
+
import { minify, getCacheStats } from 'html-minifier-next';
|
|
392
|
+
|
|
393
|
+
// After minifying pages that share templated CSS/JS…
|
|
394
|
+
for (const html of pages) {
|
|
395
|
+
await minify(html, { minifyCSS: true, minifyJS: true });
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
console.log(getCacheStats());
|
|
399
|
+
// {
|
|
400
|
+
// css: { gets: 392, hits: 298, size: 94, limit: 500 },
|
|
401
|
+
// js: { gets: 1196, hits: 1192, size: 4, limit: 500 },
|
|
402
|
+
// svg: { gets: 0, hits: 0, size: 0, limit: 500 }
|
|
403
|
+
// }
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
A cache that was never exercised (e.g., `minifySVG` disabled, or `minify()` not yet called) reports all-zero stats.
|
|
407
|
+
|
|
408
|
+
The CLI’s `--verbose` and `--dry` modes print the same information to STDERR at the end of a run, omitting caches that were never touched.
|
|
409
|
+
|
|
385
410
|
## Minification comparison
|
|
386
411
|
|
|
387
412
|
Please see [**the Minifier Benchmarks project**](https://github.com/j9t/minifier-benchmarks) for details on how HTML Minifier Next compares to other minifiers.
|
|
@@ -407,8 +432,8 @@ npx html-minifier-next --collapse-whitespace --input-dir=src --output-dir=dist
|
|
|
407
432
|
# Process only specific extensions
|
|
408
433
|
npx html-minifier-next --collapse-whitespace --input-dir=src --output-dir=dist --file-ext=html,php
|
|
409
434
|
|
|
410
|
-
# Using configuration file that sets `fileExt` (e.g., `"fileExt": "html,php"`)
|
|
411
|
-
npx html-minifier-next --config-file=
|
|
435
|
+
# Using a configuration file that sets `fileExt` (e.g., `"fileExt": "html,php"`)
|
|
436
|
+
npx html-minifier-next --config-file=path/to/config.json --input-dir=src --output-dir=dist
|
|
412
437
|
|
|
413
438
|
# Process all files (explicit wildcard)
|
|
414
439
|
npx html-minifier-next --collapse-whitespace --input-dir=src --output-dir=dist --file-ext='*'
|
|
@@ -501,7 +526,7 @@ This minifier includes protection against regular expression denial of service (
|
|
|
501
526
|
|
|
502
527
|
**Safe patterns** (recommended):
|
|
503
528
|
|
|
504
|
-
```
|
|
529
|
+
```js
|
|
505
530
|
ignoreCustomFragments: [
|
|
506
531
|
/<%[\s\S]{0,1000}?%>/, // JSP/ASP with explicit bounds
|
|
507
532
|
/<\?php[\s\S]{0,5000}?\?>/, // PHP with bounds
|
|
@@ -511,7 +536,7 @@ ignoreCustomFragments: [
|
|
|
511
536
|
|
|
512
537
|
**Potentially unsafe patterns** (will trigger warnings):
|
|
513
538
|
|
|
514
|
-
```
|
|
539
|
+
```js
|
|
515
540
|
ignoreCustomFragments: [
|
|
516
541
|
/<%[\s\S]*?%>/, // Unlimited quantifiers
|
|
517
542
|
/<!--[\s\S]*?-->/, // Could cause issues with very long comments
|
|
@@ -522,7 +547,7 @@ ignoreCustomFragments: [
|
|
|
522
547
|
|
|
523
548
|
**Template engine configurations:**
|
|
524
549
|
|
|
525
|
-
```
|
|
550
|
+
```js
|
|
526
551
|
// Handlebars/Mustache
|
|
527
552
|
ignoreCustomFragments: [/\{\{[\s\S]{0,1000}?\}\}/]
|
|
528
553
|
|
|
@@ -552,14 +577,14 @@ The escaping requirements for `ignoreCustomFragments` patterns differ depending
|
|
|
552
577
|
|
|
553
578
|
**Programmatic (JavaScript/Node.js):**
|
|
554
579
|
|
|
555
|
-
```
|
|
580
|
+
```js
|
|
556
581
|
ignoreCustomFragments: [/\{%[\s\S]{0,1000}?%\}/, /\{\{[\s\S]{0,500}?\}\}/]
|
|
557
582
|
```
|
|
558
583
|
|
|
559
584
|
**CLI (via config file—recommended):**
|
|
560
585
|
|
|
561
586
|
```shell
|
|
562
|
-
npx html-minifier-next --config-file=config.json input.html
|
|
587
|
+
npx html-minifier-next --config-file=path/to/config.json input.html
|
|
563
588
|
```
|
|
564
589
|
|
|
565
590
|
**CLI (inline—not recommended due to complex escaping):**
|
|
@@ -620,7 +645,7 @@ Parameters:
|
|
|
620
645
|
* `--save`: Saves the run as the baseline (e.g., on `main` before switching to a branch)
|
|
621
646
|
* `--core`: Disables the external minifiers (CSS, JS, SVG, URLs) to isolate HMN’s own processing time
|
|
622
647
|
* `--iterations=N`: Sets the number of timed iterations (default 5; the median is reported)
|
|
623
|
-
* `--config=PATH`: Uses an alternative options file (default `html-minifier-next.json`)
|
|
648
|
+
* `--config=PATH`: Uses an alternative options file (default `html-minifier-next.config.json`)
|
|
624
649
|
|
|
625
650
|
To compare branches (A/B run), execute `npm run benchmark -- --save` on `main`, then `npm run benchmark` on the branch to see the deltas. Add `--core` on both ends when measuring changes to HMN’s own code rather than the bundled minifiers.
|
|
626
651
|
|
|
@@ -642,6 +667,6 @@ With many thanks to the previous authors of and contributors to HTML Minifier, e
|
|
|
642
667
|
|
|
643
668
|
You might like some of my other work:
|
|
644
669
|
|
|
645
|
-
* Optimization tools: [hihtml](https://github.com/j9t/hihtml) · HTML Minifier Next · [ObsoHTML](https://github.com/j9t/obsohtml) · [Image Guard](https://github.com/j9t/image-guard) · [Compressor.js Next](https://github.com/j9t/compressorjs-next) · [.htaccess Punk](https://github.com/j9t/htaccess-punk)
|
|
670
|
+
* Optimization tools: [hihtml](https://github.com/j9t/hihtml) · HTML Minifier Next · [ObsoHTML](https://github.com/j9t/obsohtml) · [CSS Dedup](https://github.com/j9t/css-dedup) · [Image Guard](https://github.com/j9t/image-guard) · [Compressor.js Next](https://github.com/j9t/compressorjs-next) · [.htaccess Punk](https://github.com/j9t/htaccess-punk)
|
|
646
671
|
* Defense tools: [IA Defensa](https://iadefensa.com/solutions/)
|
|
647
672
|
* Resources for quality web development: [Articles](https://meiert.com/topics/development/) · [Books](https://meiert.com/topics/books/) (including [_On Web Development_](https://meiert.com/blog/on-web-development-2/)) · [News](https://frontenddogma.com/) · [Terminology](https://webglossary.info/)
|
package/cli.js
CHANGED
|
@@ -229,6 +229,10 @@ async function loadConfigFromPath(configPath) {
|
|
|
229
229
|
// Config keys the CLI handles itself, beyond the options in `optionDefinitions`
|
|
230
230
|
const CONFIG_KEYS_EXTRA = new Set(['$schema', 'preset', 'fileExt', 'ignoreDir']);
|
|
231
231
|
|
|
232
|
+
// Default config files, looked up in the working directory in this order when
|
|
233
|
+
// `--config-file` isn’t specified
|
|
234
|
+
const CONFIG_FILES_DEFAULT = ['html-minifier-next.config.json', 'htmlminifier.config.json'];
|
|
235
|
+
|
|
232
236
|
/**
|
|
233
237
|
* Normalize and validate config object by applying parsers and transforming values.
|
|
234
238
|
* @param {object} config - Raw config object
|
|
@@ -387,10 +391,17 @@ program.helpOption('-h, --help', 'Display help for command');
|
|
|
387
391
|
}
|
|
388
392
|
}
|
|
389
393
|
|
|
390
|
-
// Load and normalize config if `--config-file` was specified
|
|
394
|
+
// Load and normalize config if `--config-file` was specified; otherwise look
|
|
395
|
+
// for a default config file in the working directory
|
|
391
396
|
if (programOptions.configFile) {
|
|
392
397
|
config = await loadConfigFromPath(programOptions.configFile);
|
|
393
398
|
config = normalizeConfig(config);
|
|
399
|
+
} else {
|
|
400
|
+
const configFileDefault = CONFIG_FILES_DEFAULT.find(name => fs.existsSync(path.resolve(name)));
|
|
401
|
+
if (configFileDefault) {
|
|
402
|
+
console.error(`Using config file “${configFileDefault}”`);
|
|
403
|
+
config = normalizeConfig(await loadConfigFromPath(configFileDefault));
|
|
404
|
+
}
|
|
394
405
|
}
|
|
395
406
|
|
|
396
407
|
function createOptions() {
|
|
@@ -452,6 +463,26 @@ program.helpOption('-h, --help', 'Display help for command');
|
|
|
452
463
|
return { originalSize, minifiedSize, saved, sign, percentage };
|
|
453
464
|
}
|
|
454
465
|
|
|
466
|
+
// Print a one-line-per-cache hits/misses/size summary to STDERR, skipping caches
|
|
467
|
+
// that were never touched (e.g., their minifier is disabled)
|
|
468
|
+
async function printCacheStats() {
|
|
469
|
+
const { getCacheStats } = await import('./src/htmlminifier.js');
|
|
470
|
+
const cacheStats = getCacheStats();
|
|
471
|
+
const labels = { css: 'CSS', js: 'JS', svg: 'SVG' };
|
|
472
|
+
|
|
473
|
+
const lines = Object.keys(labels).reduce((acc, key) => {
|
|
474
|
+
const { gets, hits, size, limit } = cacheStats[key];
|
|
475
|
+
if (gets === 0) return acc;
|
|
476
|
+
const misses = gets - hits;
|
|
477
|
+
acc.push(` ${labels[key]} cache: ${hits.toLocaleString()} hit${hits === 1 ? '' : 's'}, ${misses.toLocaleString()} miss${misses === 1 ? '' : 'es'}, ${size.toLocaleString()}/${limit.toLocaleString()} entries`);
|
|
478
|
+
return acc;
|
|
479
|
+
}, []);
|
|
480
|
+
|
|
481
|
+
if (lines.length === 0) return;
|
|
482
|
+
console.error('Cache stats:');
|
|
483
|
+
lines.forEach(line => console.error(line));
|
|
484
|
+
}
|
|
485
|
+
|
|
455
486
|
async function processFile(inputFile, outputFile, isDryRun = false, isVerbose = false) {
|
|
456
487
|
const data = await fs.promises.readFile(inputFile, { encoding: 'utf8' }).catch(err => {
|
|
457
488
|
fatal('Cannot read ' + inputFile + '\n' + err.message);
|
|
@@ -698,6 +729,7 @@ program.helpOption('-h, --help', 'Display help for command');
|
|
|
698
729
|
console.error(` Original: ${stats.originalSize.toLocaleString()} bytes`);
|
|
699
730
|
console.error(` Minified: ${stats.minifiedSize.toLocaleString()} bytes`);
|
|
700
731
|
console.error(` Saved: ${stats.sign}${Math.abs(stats.saved).toLocaleString()} bytes (${stats.percentage}%)`);
|
|
732
|
+
await printCacheStats();
|
|
701
733
|
return;
|
|
702
734
|
}
|
|
703
735
|
|
|
@@ -705,6 +737,7 @@ program.helpOption('-h, --help', 'Display help for command');
|
|
|
705
737
|
if (programOptions.verbose) {
|
|
706
738
|
const inputSource = program.args.length > 0 ? program.args.join(', ') : 'STDIN';
|
|
707
739
|
console.error(` ${MARK_SUCCESS}✓${MARK_RESET} ${inputSource}: ${stats.originalSize.toLocaleString()} → ${stats.minifiedSize.toLocaleString()} bytes (${stats.sign}${Math.abs(stats.saved).toLocaleString()}, ${stats.percentage}%)`);
|
|
740
|
+
await printCacheStats();
|
|
708
741
|
}
|
|
709
742
|
|
|
710
743
|
if (programOptions.output) {
|
|
@@ -833,6 +866,10 @@ program.helpOption('-h, --help', 'Display help for command');
|
|
|
833
866
|
console.error('---');
|
|
834
867
|
console.error(`Total: ${totalOriginal.toLocaleString()} → ${totalMinified.toLocaleString()} bytes (${sign}${Math.abs(totalSaved).toLocaleString()}, ${totalPercentage}%)`);
|
|
835
868
|
}
|
|
869
|
+
|
|
870
|
+
if (isVerbose) {
|
|
871
|
+
await printCacheStats();
|
|
872
|
+
}
|
|
836
873
|
})();
|
|
837
874
|
} else if (filesProvided) { // Minifying one or more files specified on the CMD line
|
|
838
875
|
// Process each file independently, then concatenate outputs
|
|
@@ -881,12 +918,14 @@ program.helpOption('-h, --help', 'Display help for command');
|
|
|
881
918
|
console.error(` Original: ${stats.originalSize.toLocaleString()} bytes`);
|
|
882
919
|
console.error(` Minified: ${stats.minifiedSize.toLocaleString()} bytes`);
|
|
883
920
|
console.error(` Saved: ${stats.sign}${Math.abs(stats.saved).toLocaleString()} bytes (${stats.percentage}%)`);
|
|
921
|
+
await printCacheStats();
|
|
884
922
|
process.exit(0);
|
|
885
923
|
}
|
|
886
924
|
|
|
887
925
|
if (programOptions.verbose) {
|
|
888
926
|
const inputSource = capturedFiles.join(', ');
|
|
889
927
|
console.error(` ${MARK_SUCCESS}✓${MARK_RESET} ${inputSource}: ${stats.originalSize.toLocaleString()} → ${stats.minifiedSize.toLocaleString()} bytes (${stats.sign}${Math.abs(stats.saved).toLocaleString()}, ${stats.percentage}%)`);
|
|
928
|
+
await printCacheStats();
|
|
890
929
|
}
|
|
891
930
|
|
|
892
931
|
if (programOptions.output) {
|
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
declare namespace _default {
|
|
3
|
-
export { minify };
|
|
4
|
-
export { presets };
|
|
5
|
-
export { getPreset };
|
|
6
|
-
export { getPresetNames };
|
|
7
|
-
}
|
|
8
|
-
export default _default;
|
|
9
|
-
/**
|
|
10
|
-
* Representation of an attribute from the HTML parser.
|
|
11
|
-
* Internal counterpart: `HTMLAttribute` in `lib/attributes.js`—keep in sync.
|
|
12
|
-
*/
|
|
1
|
+
import { presets, getPreset, getPresetNames } from './presets.js';
|
|
13
2
|
export type HTMLAttribute = {
|
|
14
3
|
name: string;
|
|
15
4
|
value?: string;
|
|
@@ -18,10 +7,6 @@ export type HTMLAttribute = {
|
|
|
18
7
|
customOpen?: string;
|
|
19
8
|
customClose?: string;
|
|
20
9
|
};
|
|
21
|
-
/**
|
|
22
|
-
* Options that control how HTML is minified. All of these are optional
|
|
23
|
-
* and usually default to a disabled/safe value unless noted.
|
|
24
|
-
*/
|
|
25
10
|
export type MinifierOptions = {
|
|
26
11
|
/**
|
|
27
12
|
* Predicate that determines whether whitespace inside a given element
|
|
@@ -264,7 +249,7 @@ export type MinifierOptions = {
|
|
|
264
249
|
* Default: `false`
|
|
265
250
|
*/
|
|
266
251
|
minifyJS?: boolean | import("terser").MinifyOptions | {
|
|
267
|
-
engine?:
|
|
252
|
+
engine?: 'terser' | 'swc';
|
|
268
253
|
[key: string]: any;
|
|
269
254
|
} | ((text: string, inline?: boolean) => Promise<string> | string);
|
|
270
255
|
/**
|
|
@@ -470,8 +455,80 @@ export type MinifierOptions = {
|
|
|
470
455
|
*/
|
|
471
456
|
useShortDoctype?: boolean;
|
|
472
457
|
};
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
458
|
+
export type CacheStats = {
|
|
459
|
+
/**
|
|
460
|
+
* Number of lookups attempted against the cache.
|
|
461
|
+
*/
|
|
462
|
+
gets: number;
|
|
463
|
+
/**
|
|
464
|
+
* Number of lookups that found a cached entry.
|
|
465
|
+
*/
|
|
466
|
+
hits: number;
|
|
467
|
+
/**
|
|
468
|
+
* Number of entries currently held in the cache.
|
|
469
|
+
*/
|
|
470
|
+
size: number;
|
|
471
|
+
/**
|
|
472
|
+
* Maximum number of entries the cache can hold.
|
|
473
|
+
*/
|
|
474
|
+
limit: number;
|
|
475
|
+
};
|
|
476
|
+
/**
|
|
477
|
+
* Get hit/miss statistics for the CSS, JavaScript, and SVG minification caches.
|
|
478
|
+
*
|
|
479
|
+
* Each cache is created lazily on the first `minify()` call (see `initCaches`); before
|
|
480
|
+
* that first call, or for a cache never exercised (e.g., `minifyCSS` disabled), its
|
|
481
|
+
* entry reports all-zero stats.
|
|
482
|
+
*
|
|
483
|
+
* @returns {{ css: CacheStats, js: CacheStats, svg: CacheStats }}
|
|
484
|
+
*/
|
|
485
|
+
export declare function getCacheStats(): {
|
|
486
|
+
css: CacheStats;
|
|
487
|
+
js: CacheStats;
|
|
488
|
+
svg: CacheStats;
|
|
489
|
+
};
|
|
490
|
+
/**
|
|
491
|
+
* @param {string} value
|
|
492
|
+
* @param {MinifierOptions} [options]
|
|
493
|
+
* @returns {Promise<string>}
|
|
494
|
+
*/
|
|
495
|
+
export declare const minify: (value: string, options?: MinifierOptions) => Promise<string>;
|
|
476
496
|
export { presets, getPreset, getPresetNames };
|
|
497
|
+
declare const _default: {
|
|
498
|
+
minify: typeof minify;
|
|
499
|
+
presets: {
|
|
500
|
+
conservative: {
|
|
501
|
+
caseSensitive: boolean;
|
|
502
|
+
collapseBooleanAttributes: boolean;
|
|
503
|
+
collapseWhitespace: boolean;
|
|
504
|
+
conservativeCollapse: boolean;
|
|
505
|
+
preserveLineBreaks: boolean;
|
|
506
|
+
removeComments: boolean;
|
|
507
|
+
removeDefaultTypeAttributes: boolean;
|
|
508
|
+
useShortDoctype: boolean;
|
|
509
|
+
};
|
|
510
|
+
comprehensive: {
|
|
511
|
+
collapseAttributeWhitespace: boolean;
|
|
512
|
+
collapseBooleanAttributes: boolean;
|
|
513
|
+
collapseWhitespace: boolean;
|
|
514
|
+
decodeEntities: boolean;
|
|
515
|
+
mergeScripts: boolean;
|
|
516
|
+
minifyCSS: boolean;
|
|
517
|
+
minifyJS: boolean;
|
|
518
|
+
minifySVG: boolean;
|
|
519
|
+
minifyURLs: boolean;
|
|
520
|
+
removeAttributeQuotes: boolean;
|
|
521
|
+
removeComments: boolean;
|
|
522
|
+
removeDefaultTypeAttributes: boolean;
|
|
523
|
+
removeEmptyAttributes: boolean;
|
|
524
|
+
removeOptionalTags: boolean;
|
|
525
|
+
removeRedundantAttributes: boolean;
|
|
526
|
+
useShortDoctype: boolean;
|
|
527
|
+
};
|
|
528
|
+
};
|
|
529
|
+
getPreset: typeof getPreset;
|
|
530
|
+
getPresetNames: typeof getPresetNames;
|
|
531
|
+
getCacheStats: typeof getCacheStats;
|
|
532
|
+
};
|
|
533
|
+
export default _default;
|
|
477
534
|
//# sourceMappingURL=htmlminifier.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"htmlminifier.d.ts","sourceRoot":"","sources":["../../src/htmlminifier.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"html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AAE,SAAS,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
export const endTag: RegExp;
|
|
2
|
-
export class HTMLParser {
|
|
3
|
-
/**
|
|
4
|
-
* @param {string} html
|
|
5
|
-
* @param {HTMLParserHandler} handler
|
|
6
|
-
*/
|
|
7
|
-
constructor(html: string, handler: HTMLParserHandler);
|
|
8
|
-
html: string;
|
|
9
|
-
handler: HTMLParserHandler;
|
|
10
|
-
parse(): Promise<void>;
|
|
11
|
-
}
|
|
12
1
|
export type HTMLParserHandler = {
|
|
13
2
|
start?: Function;
|
|
14
3
|
end?: Function;
|
|
@@ -21,4 +10,15 @@ export type HTMLParserHandler = {
|
|
|
21
10
|
customAttrSurround?: RegExp[][] | undefined;
|
|
22
11
|
customAttrAssign?: RegExp[] | undefined;
|
|
23
12
|
};
|
|
13
|
+
export declare const endTag: RegExp;
|
|
14
|
+
export declare class HTMLParser {
|
|
15
|
+
html: string;
|
|
16
|
+
handler: HTMLParserHandler;
|
|
17
|
+
/**
|
|
18
|
+
* @param {string} html
|
|
19
|
+
* @param {HTMLParserHandler} handler
|
|
20
|
+
*/
|
|
21
|
+
constructor(html: string, handler: HTMLParserHandler);
|
|
22
|
+
parse(): Promise<void>;
|
|
23
|
+
}
|
|
24
24
|
//# sourceMappingURL=htmlparser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"htmlparser.d.ts","sourceRoot":"","sources":["../../src/htmlparser.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"htmlparser.d.ts","sourceRoot":"","sources":["../../src/htmlparser.js"],"names":[],"mappings":"AAcG,YAWG,iBAAiB,GAXV;IACR,KAAK,CAAC,WAAW;IACjB,GAAG,CAAC,WAAW;IACf,KAAK,CAAC,WAAW;IACjB,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,WAAW;IACnB,oBAAoB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC3C,aAAa,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACpC,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACnC,kBAAkB,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,SAAS,CAAC;IAC5C,gBAAgB,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;CACxC,CAAmB;AAgDvB,eAAO,MAAM,MAAM,QAA8C,CAAC;AA2HlE,qBAAa,UAAU;IAMd,IAAI;IACJ,OAAO;IANd;;;OAGG;IACH,YAAY,IAAI,EAHL,MAGK,EAAE,OAAO,EAFd,iBAEc,EAGxB;IAEK,KAAK,kBA4nBV;CACF"}
|