html-minifier-next 7.3.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 +9 -9
- package/cli.js +12 -1
- package/package.json +8 -8
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
|
|
|
@@ -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
|
|
@@ -432,8 +432,8 @@ npx html-minifier-next --collapse-whitespace --input-dir=src --output-dir=dist
|
|
|
432
432
|
# Process only specific extensions
|
|
433
433
|
npx html-minifier-next --collapse-whitespace --input-dir=src --output-dir=dist --file-ext=html,php
|
|
434
434
|
|
|
435
|
-
# Using configuration file that sets `fileExt` (e.g., `"fileExt": "html,php"`)
|
|
436
|
-
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
|
|
437
437
|
|
|
438
438
|
# Process all files (explicit wildcard)
|
|
439
439
|
npx html-minifier-next --collapse-whitespace --input-dir=src --output-dir=dist --file-ext='*'
|
|
@@ -584,7 +584,7 @@ ignoreCustomFragments: [/\{%[\s\S]{0,1000}?%\}/, /\{\{[\s\S]{0,500}?\}\}/]
|
|
|
584
584
|
**CLI (via config file—recommended):**
|
|
585
585
|
|
|
586
586
|
```shell
|
|
587
|
-
npx html-minifier-next --config-file=config.json input.html
|
|
587
|
+
npx html-minifier-next --config-file=path/to/config.json input.html
|
|
588
588
|
```
|
|
589
589
|
|
|
590
590
|
**CLI (inline—not recommended due to complex escaping):**
|
|
@@ -645,7 +645,7 @@ Parameters:
|
|
|
645
645
|
* `--save`: Saves the run as the baseline (e.g., on `main` before switching to a branch)
|
|
646
646
|
* `--core`: Disables the external minifiers (CSS, JS, SVG, URLs) to isolate HMN’s own processing time
|
|
647
647
|
* `--iterations=N`: Sets the number of timed iterations (default 5; the median is reported)
|
|
648
|
-
* `--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`)
|
|
649
649
|
|
|
650
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.
|
|
651
651
|
|
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() {
|
package/package.json
CHANGED
|
@@ -9,21 +9,21 @@
|
|
|
9
9
|
"commander": "^15.0.0",
|
|
10
10
|
"entities": "^8.0.0",
|
|
11
11
|
"lightningcss": "^1.32.0",
|
|
12
|
-
"svgo": "^4.0.
|
|
13
|
-
"terser": "^5.
|
|
12
|
+
"svgo": "^4.0.2",
|
|
13
|
+
"terser": "^5.49.0"
|
|
14
14
|
},
|
|
15
15
|
"description": "Super-configurable and well-tested web page minifier (enhanced successor to HTML Minifier)",
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@commitlint/cli": "^21.2.
|
|
17
|
+
"@commitlint/cli": "^21.2.1",
|
|
18
18
|
"@eslint/js": "^10.0.1",
|
|
19
|
-
"@swc/core": "^1.15.
|
|
19
|
+
"@swc/core": "^1.15.43",
|
|
20
20
|
"@types/node": "^26.1.1",
|
|
21
|
-
"eslint": "^10.
|
|
21
|
+
"eslint": "^10.7.0",
|
|
22
22
|
"typescript": "^7.0.2",
|
|
23
|
-
"vite": "^8.
|
|
23
|
+
"vite": "^8.1.5"
|
|
24
24
|
},
|
|
25
25
|
"engines": {
|
|
26
|
-
"node": ">=22"
|
|
26
|
+
"node": ">=22.13"
|
|
27
27
|
},
|
|
28
28
|
"exports": {
|
|
29
29
|
".": {
|
|
@@ -93,5 +93,5 @@
|
|
|
93
93
|
"test:watch": "node --test --watch tests/*.spec.js"
|
|
94
94
|
},
|
|
95
95
|
"type": "module",
|
|
96
|
-
"version": "7.
|
|
96
|
+
"version": "7.4.0"
|
|
97
97
|
}
|