html-minifier-next 6.2.8 → 6.2.10
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 +38 -3
- package/cli.js +9 -4
- package/dist/htmlminifier.cjs +882 -557
- package/dist/types/htmlminifier.d.ts +77 -60
- package/dist/types/htmlminifier.d.ts.map +1 -1
- package/dist/types/htmlparser.d.ts +19 -3
- package/dist/types/htmlparser.d.ts.map +1 -1
- package/dist/types/lib/attributes.d.ts +137 -23
- package/dist/types/lib/attributes.d.ts.map +1 -1
- package/dist/types/lib/content.d.ts +37 -5
- package/dist/types/lib/content.d.ts.map +1 -1
- package/dist/types/lib/elements.d.ts +29 -4
- package/dist/types/lib/elements.d.ts.map +1 -1
- package/dist/types/lib/options.d.ts +17 -14
- package/dist/types/lib/options.d.ts.map +1 -1
- package/dist/types/lib/utils.d.ts +28 -11
- package/dist/types/lib/utils.d.ts.map +1 -1
- package/dist/types/lib/whitespace.d.ts +40 -6
- package/dist/types/lib/whitespace.d.ts.map +1 -1
- package/dist/types/tokenchain.d.ts +17 -3
- package/dist/types/tokenchain.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/htmlminifier.js +405 -346
- package/src/htmlparser.js +101 -48
- package/src/lib/attributes.js +166 -50
- package/src/lib/content.js +28 -12
- package/src/lib/elements.js +30 -7
- package/src/lib/options.js +55 -42
- package/src/lib/utils.js +26 -7
- package/src/lib/whitespace.js +30 -11
- package/src/presets.js +1 -1
- package/src/tokenchain.js +30 -17
package/README.md
CHANGED
|
@@ -34,7 +34,8 @@ Use `npx html-minifier-next --help` to check all available options:
|
|
|
34
34
|
| `--input-dir <dir>`, `-I <dir>` | Specify an input directory | `--input-dir=src` |
|
|
35
35
|
| `--ignore-dir <patterns>`, `-X <patterns>` | Exclude directories—relative to input directory—from processing (comma-separated, overrides config file setting) | `--ignore-dir=libs`, `--ignore-dir=libs,vendor,node_modules` |
|
|
36
36
|
| `--output-dir <dir>`, `-O <dir>` | Specify an output directory | `--output-dir=dist` |
|
|
37
|
-
| `--
|
|
37
|
+
| `--input <file>`, `-i <file>` | Specify input file (alternative to positional argument; pair with `--output` for file output) | `npx html-minifier-next -i input.html -o output.html` |
|
|
38
|
+
| `--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` |
|
|
38
39
|
| `--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='*'` |
|
|
39
40
|
| `--preset <name>`, `-p <name>` | Use a preset configuration (conservative or comprehensive) | `--preset=conservative` |
|
|
40
41
|
| `--config-file <file>`, `-c <file>` | Use a configuration file | `--config-file=html-minifier.json` |
|
|
@@ -179,7 +180,7 @@ Options can be used in config files (camelCase) or via CLI flags (kebab-case wit
|
|
|
179
180
|
|
|
180
181
|
### Sorting attributes and style classes
|
|
181
182
|
|
|
182
|
-
Minifier options like `sortAttributes` and `sortClassNames` won’t impact the plain
|
|
183
|
+
Minifier options like `sortAttributes` and `sortClassNames` won’t impact the plain-text size of the output. However, using these options for more consistent ordering improves the compression ratio for Gzip and Brotli used over HTTP.
|
|
183
184
|
|
|
184
185
|
### CSS minification
|
|
185
186
|
|
|
@@ -567,6 +568,8 @@ For CLI usage, using a config file is strongly recommended to avoid complex shel
|
|
|
567
568
|
|
|
568
569
|
## Working on HTML Minifier Next
|
|
569
570
|
|
|
571
|
+
Note: This section assumes working with main dependencies installed (`npm i`).
|
|
572
|
+
|
|
570
573
|
### Local server
|
|
571
574
|
|
|
572
575
|
```shell
|
|
@@ -581,7 +584,7 @@ npm i;
|
|
|
581
584
|
npm run backtest
|
|
582
585
|
```
|
|
583
586
|
|
|
584
|
-
The backtest tool tracks minification performance across Git history. Results are saved in the backtest folder as
|
|
587
|
+
The backtest tool tracks minification performance across Git history. Results are saved in the backtest folder as a JSON file, results.json.
|
|
585
588
|
|
|
586
589
|
Parameters:
|
|
587
590
|
|
|
@@ -589,6 +592,38 @@ Parameters:
|
|
|
589
592
|
* `COUNT`: Tests last `COUNT` commits (e.g., `npm run backtest 100`)
|
|
590
593
|
* `COUNT/STEP`: Tests last `COUNT` commits, sampling every `STEP`th commit (e.g., `npm run backtest 500/10` tests 50 commits)
|
|
591
594
|
|
|
595
|
+
### Working tree benchmarks
|
|
596
|
+
|
|
597
|
+
Where the backtest walks Git history, the benchmark times the code as it is _right now_—useful for A/B testing a branch against a saved baseline:
|
|
598
|
+
|
|
599
|
+
```shell
|
|
600
|
+
cd backtest;
|
|
601
|
+
npm i;
|
|
602
|
+
npm run benchmark
|
|
603
|
+
```
|
|
604
|
+
|
|
605
|
+
It reuses the backtest corpus (run `npm run backtest` once to download it) and reports per-file output size and median processing time.
|
|
606
|
+
|
|
607
|
+
Parameters:
|
|
608
|
+
|
|
609
|
+
* No argument: Runs and, if a baseline exists, shows size and time deltas
|
|
610
|
+
* `--save`: Saves the run as the baseline (e.g., on `main` before switching to a branch)
|
|
611
|
+
* `--core`: Disables the external minifiers (CSS, JS, SVG, URLs) to isolate HMN’s own processing time
|
|
612
|
+
* `--iterations=N`: Sets the number of timed iterations (default 5; the median is reported)
|
|
613
|
+
* `--config=PATH`: Uses an alternative options file (default `html-minifier.json`)
|
|
614
|
+
|
|
615
|
+
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.
|
|
616
|
+
|
|
617
|
+
#### Profiling
|
|
618
|
+
|
|
619
|
+
To profile the current working tree, run the benchmark with Node’s built-in CPU profiler:
|
|
620
|
+
|
|
621
|
+
```shell
|
|
622
|
+
node --cpu-prof benchmark.js
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
This writes a `.cpuprofile` file to the working directory. Load it with `npx speedscope *.cpuprofile` for a flamegraph, or drag it into Chrome DevTools → Sources → JavaScript Profiler. Compare self-time per function against a clean baseline run on `main`. Pay attention to unexpectedly heavy callbacks in hot paths—V8 de-optimization from variable object shapes or unnecessary method calls can show up there.
|
|
626
|
+
|
|
592
627
|
## Acknowledgements
|
|
593
628
|
|
|
594
629
|
With many thanks to the previous authors of and contributors to HTML Minifier, especially [Juriy “kangax” Zaytsev](https://github.com/kangax), and to everyone who helped make this new edition better, particularly [Daniel Ruf](https://github.com/DanielRuf), [Jonas Geiler](https://github.com/jonasgeiler), and [Chris Morgan](https://github.com/chris-morgan)!
|
package/cli.js
CHANGED
|
@@ -171,7 +171,8 @@ mainOptionKeys.forEach(function (key) {
|
|
|
171
171
|
program.option(cliFlag, description, parser);
|
|
172
172
|
}
|
|
173
173
|
});
|
|
174
|
-
program.option('-
|
|
174
|
+
program.option('-i --input <file>', 'Specify input file (alternative to positional argument; pair with `--output` for output)');
|
|
175
|
+
program.option('-o --output <file>', 'Specify output file (reads from `--input` file argument or STDIN; outputs to STDOUT if not specified)');
|
|
175
176
|
program.option('-v --verbose', 'Show detailed processing information');
|
|
176
177
|
program.option('-d --dry', 'Dry run: Process and report statistics without writing output');
|
|
177
178
|
program.addHelpText('after', '\nBoolean options support a `--no-<flag>` form to disable them, overriding a preset or config file (e.g., `--preset=comprehensive --no-collapse-whitespace`).');
|
|
@@ -318,7 +319,11 @@ program.helpOption('-h, --help', 'Display help for command');
|
|
|
318
319
|
}
|
|
319
320
|
}
|
|
320
321
|
|
|
321
|
-
//
|
|
322
|
+
// If `--input` was specified, treat it as a positional file argument
|
|
323
|
+
if (programOptions.input) {
|
|
324
|
+
capturedFiles.unshift(programOptions.input);
|
|
325
|
+
filesProvided = true;
|
|
326
|
+
}
|
|
322
327
|
|
|
323
328
|
// Handle zero config mode (standalone in-place minification of the current folder)
|
|
324
329
|
if (programOptions.zero) {
|
|
@@ -735,7 +740,7 @@ program.helpOption('-h, --help', 'Display help for command');
|
|
|
735
740
|
|
|
736
741
|
if (inputDir || outputDir) {
|
|
737
742
|
if (!inputDir) {
|
|
738
|
-
fatal('The option `output-dir` needs to be used with the option `input-dir`—if you are working with a single file, use
|
|
743
|
+
fatal('The option `output-dir` needs to be used with the option `input-dir`—if you are working with a single file, use `--input`/`--output`');
|
|
739
744
|
} else if (!outputDir) {
|
|
740
745
|
fatal('You need to specify where to write the output files with the option `--output-dir`');
|
|
741
746
|
}
|
|
@@ -780,7 +785,7 @@ program.helpOption('-h, --help', 'Display help for command');
|
|
|
780
785
|
try {
|
|
781
786
|
const stat = await fs.promises.stat(inputDir);
|
|
782
787
|
if (!stat.isDirectory()) {
|
|
783
|
-
fatal(inputDir
|
|
788
|
+
fatal(`${inputDir} is not a directory—to minify a single file, use \`--input\`/\`--output\`: html-minifier-next [options] -i ${inputDir} -o <output-file>`);
|
|
784
789
|
}
|
|
785
790
|
} catch (err) {
|
|
786
791
|
fatal('Cannot read directory ' + inputDir + '\n' + err.message);
|