html-minifier-next 6.2.9 → 6.2.11
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 +3 -2
- package/cli.js +30 -7
- package/package.json +2 -2
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
|
|
package/cli.js
CHANGED
|
@@ -58,7 +58,8 @@ import { optionDefinitions } from './src/lib/option-definitions.js';
|
|
|
58
58
|
const require = createRequire(import.meta.url);
|
|
59
59
|
const pkg = require('./package.json');
|
|
60
60
|
|
|
61
|
-
const
|
|
61
|
+
const EXTENSIONS_DEFAULT = ['html', 'htm', 'shtml', 'shtm'];
|
|
62
|
+
const EXTENSIONS_NON_HTML = new Set(['css', 'js', 'mjs', 'cjs', 'jsx', 'ts', 'tsx', 'svg']);
|
|
62
63
|
|
|
63
64
|
const MARK_ERROR = process.stderr.isTTY ? '\x1b[31m' : '';
|
|
64
65
|
const MARK_SUCCESS = process.stderr.isTTY ? '\x1b[32m' : '';
|
|
@@ -171,7 +172,8 @@ mainOptionKeys.forEach(function (key) {
|
|
|
171
172
|
program.option(cliFlag, description, parser);
|
|
172
173
|
}
|
|
173
174
|
});
|
|
174
|
-
program.option('-
|
|
175
|
+
program.option('-i --input <file>', 'Specify input file (alternative to positional argument; pair with `--output` for output)');
|
|
176
|
+
program.option('-o --output <file>', 'Specify output file (reads from `--input` file argument or STDIN; outputs to STDOUT if not specified)');
|
|
175
177
|
program.option('-v --verbose', 'Show detailed processing information');
|
|
176
178
|
program.option('-d --dry', 'Dry run: Process and report statistics without writing output');
|
|
177
179
|
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 +320,11 @@ program.helpOption('-h, --help', 'Display help for command');
|
|
|
318
320
|
}
|
|
319
321
|
}
|
|
320
322
|
|
|
321
|
-
//
|
|
323
|
+
// If `--input` was specified, treat it as a positional file argument
|
|
324
|
+
if (programOptions.input) {
|
|
325
|
+
capturedFiles.unshift(programOptions.input);
|
|
326
|
+
filesProvided = true;
|
|
327
|
+
}
|
|
322
328
|
|
|
323
329
|
// Handle zero config mode (standalone in-place minification of the current folder)
|
|
324
330
|
if (programOptions.zero) {
|
|
@@ -357,7 +363,7 @@ program.helpOption('-h, --help', 'Display help for command');
|
|
|
357
363
|
programOptions.preset = 'comprehensive';
|
|
358
364
|
|
|
359
365
|
const inputDirResolved = await fs.promises.realpath(cwd).catch(() => cwd);
|
|
360
|
-
const extensions =
|
|
366
|
+
const extensions = EXTENSIONS_DEFAULT;
|
|
361
367
|
const ignorePatterns = ['node_modules'];
|
|
362
368
|
|
|
363
369
|
const showProgress = process.stderr.isTTY;
|
|
@@ -727,7 +733,7 @@ program.helpOption('-h, --help', 'Display help for command');
|
|
|
727
733
|
|
|
728
734
|
// Resolve file extensions: CLI argument > config file > defaults
|
|
729
735
|
const hasCliFileExt = program.getOptionValueSource('fileExt') === 'cli';
|
|
730
|
-
const resolvedFileExt = hasCliFileExt ? (fileExt || '*') : (config.fileExt ||
|
|
736
|
+
const resolvedFileExt = hasCliFileExt ? (fileExt || '*') : (config.fileExt || EXTENSIONS_DEFAULT);
|
|
731
737
|
|
|
732
738
|
// Resolve ignore patterns: CLI argument takes priority over config file
|
|
733
739
|
const hasCliIgnoreDir = program.getOptionValueSource('ignoreDir') === 'cli';
|
|
@@ -735,11 +741,21 @@ program.helpOption('-h, --help', 'Display help for command');
|
|
|
735
741
|
|
|
736
742
|
if (inputDir || outputDir) {
|
|
737
743
|
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
|
|
744
|
+
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
745
|
} else if (!outputDir) {
|
|
740
746
|
fatal('You need to specify where to write the output files with the option `--output-dir`');
|
|
741
747
|
}
|
|
742
748
|
|
|
749
|
+
{
|
|
750
|
+
const extList = Array.isArray(resolvedFileExt) ? resolvedFileExt : parseFileExtensions(String(resolvedFileExt || ''));
|
|
751
|
+
const isWildcard = extList.includes('*');
|
|
752
|
+
const nonHtmlExts = isWildcard ? [] : extList.filter(e => EXTENSIONS_NON_HTML.has(e));
|
|
753
|
+
if (isWildcard || nonHtmlExts.length > 0) {
|
|
754
|
+
const label = isWildcard ? 'all file types' : nonHtmlExts.map(e => `.${e}`).join(', ');
|
|
755
|
+
console.error(`${MARK_WARNING}Warning: Processing ${label}—HTML Minifier Next processes CSS, JavaScript, and SVG only when embedded in HTML. Non-HTML files may produce incomplete or broken output.${MARK_RESET}`);
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
|
|
743
759
|
await (async () => {
|
|
744
760
|
// `--dry` automatically enables verbose mode
|
|
745
761
|
const isVerbose = programOptions.verbose || programOptions.dry;
|
|
@@ -780,7 +796,7 @@ program.helpOption('-h, --help', 'Display help for command');
|
|
|
780
796
|
try {
|
|
781
797
|
const stat = await fs.promises.stat(inputDir);
|
|
782
798
|
if (!stat.isDirectory()) {
|
|
783
|
-
fatal(inputDir
|
|
799
|
+
fatal(`${inputDir} is not a directory—to minify a single file, use \`--input\`/\`--output\`: html-minifier-next [options] -i ${inputDir} -o <output-file>`);
|
|
784
800
|
}
|
|
785
801
|
} catch (err) {
|
|
786
802
|
fatal('Cannot read directory ' + inputDir + '\n' + err.message);
|
|
@@ -835,6 +851,13 @@ program.helpOption('-h, --help', 'Display help for command');
|
|
|
835
851
|
getActiveOptionsDisplay(minifierOptions);
|
|
836
852
|
}
|
|
837
853
|
|
|
854
|
+
for (const file of capturedFiles) {
|
|
855
|
+
const ext = path.extname(file).replace(/^\./, '').toLowerCase();
|
|
856
|
+
if (EXTENSIONS_NON_HTML.has(ext)) {
|
|
857
|
+
console.error(`${MARK_WARNING}Warning: “${path.basename(file)}” does not appear to be an HTML file—HTML Minifier Next processes CSS, JavaScript, and SVG only when embedded in HTML. The output may be incomplete or broken.${MARK_RESET}`);
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
|
|
838
861
|
const concurrency = Math.max(1, Math.min(os.cpus().length || 4, 8));
|
|
839
862
|
const inputs = capturedFiles.slice();
|
|
840
863
|
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"@commitlint/cli": "^21.0.1",
|
|
18
18
|
"@eslint/js": "^10.0.1",
|
|
19
|
-
"@rollup/plugin-commonjs": "^29.0.
|
|
19
|
+
"@rollup/plugin-commonjs": "^29.0.3",
|
|
20
20
|
"@rollup/plugin-json": "^6.1.0",
|
|
21
21
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
22
22
|
"@swc/core": "^1.15.40",
|
|
@@ -98,5 +98,5 @@
|
|
|
98
98
|
},
|
|
99
99
|
"type": "module",
|
|
100
100
|
"types": "./dist/types/htmlminifier.d.ts",
|
|
101
|
-
"version": "6.2.
|
|
101
|
+
"version": "6.2.11"
|
|
102
102
|
}
|