CLI

You can compress files using the command line.

Installation

npm install -g @node-minify/cli # OR yarn global add @node-minify/cli OR pnpm add -g @node-minify/cli OR bun add -g @node-minify/cli

Usage

node-minify --compressor uglify-js --input 'input.js' --output 'output.js'
cli

Multiple Inputs

To compress multiple files, you can pass multiple --input (or -i) flags. Each value is treated as a single file path, which allows supporting paths that contain commas.

node-minify --compressor uglify-js --input 'file1.js' --input 'file2.js' --output 'bundle.min.js'

Alternatively, you can use wildcards (globs):

node-minify --compressor uglify-js --input 'src/**/*.js' --output 'bundle.min.js'

For programmatic usage, pass an array of file paths:

await run({
  compressor: "terser",
  input: ["src/a.js", "src/b.js"],
  output: "dist/bundle.min.js",
});

Custom Compressors

The CLI supports custom compressors in addition to built-in ones:

# Use an npm package as compressor
node-minify --compressor my-custom-compressor --input 'input.js' --output 'output.js'

# Use a local file as compressor
node-minify --compressor ./my-compressor.js --input 'input.js' --output 'output.js'

See the Custom Compressors documentation for details on creating your own compressor.

Options

You can pass an option as a JSON string to the compressor.

node-minify --compressor uglify-js --input 'input.js' --output 'output.js' --option '{"warnings": true, "mangle": false}'

Allowing Empty Output

When minifying files that produce empty output (e.g., CSS with only comments), use --allow-empty-output to skip writing instead of throwing an error.

node-minify --compressor clean-css --input 'comments-only.css' --output 'output.css' --allow-empty-output

Benchmark Command

Compare the performance of different compressors using the benchmark command.

Basic Usage

node-minify benchmark src/app.js

Compare Specific Compressors

node-minify benchmark src/app.js --compressors terser,esbuild,swc,oxc

With Options

# Run 3 iterations, include gzip size, specify JS type
node-minify benchmark src/app.js -c terser,esbuild -n 3 --gzip -t js

Output Formats

# Console output (default)
node-minify benchmark src/app.js -c terser,esbuild

# JSON output
node-minify benchmark src/app.js -c terser,esbuild -f json

# Markdown output
node-minify benchmark src/app.js -c terser,esbuild -f markdown

Benchmark Options

OptionDescriptionDefault
-c, --compressorsComma-separated list of compressorsterser,esbuild,swc,oxc
-n, --iterationsNumber of iterations1
-f, --formatOutput format: console, json, markdownconsole
-o, --outputOutput file pathstdout
--gzipInclude gzip size in resultsfalse
-t, --typeFile type: js, css, htmlauto-detect

Example Output

🔍 Benchmarking: src/app.js (45.2 KB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Compressor      Size      Reduction   Time      Status
──────────────────────────────────────────────────────
terser          11.8 KB   73.9%       234ms     OK
esbuild         12.3 KB   72.8%       45ms      OK

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

🏆 Best compression: terser
⚡ Fastest: esbuild
💡 Recommended: esbuild