New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

minifier-cli

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

minifier-cli

A CLI tool to minify JavaScript, CSS, and HTML files recursively.

latest
npmnpm
Version
1.2.3
Version published
Maintainers
1
Created
Source

Minifier CLI Documentation

Minifier CLI is a powerful node command-line tool designed to minify JavaScript, CSS, and HTML files recursively within a specified directory or for individual files. It leverages popular minification libraries like Terser, cssnano, and html-minifier-terser to achieve optimal file size reduction.

Table of Contents

  • Installation
  • Usage
  • Configuration Options Reference
  • Ignore Patterns Reference
  • Examples

Installation

To install Minifier CLI globally on your system, open your terminal or command prompt and run the following command:

npm install -g minifier-cli
#or
yarn add -g minifier-cli

This will make the minifier command available system-wide.

Usage

The minifier command follows a simple structure:

minifier <path> [options]

Basic Usage

You must provide a <path> argument, which can be either a file or a directory.

  • Minify the current directory:

    minifier .
    
  • Minify a specific directory:

    minifier my_project/
    
  • Minify a single file:

    minifier public/index.html
    # or
    minifier src/app.js
    # or
    minifier assets/styles.css
    

Minifying Files and Directories

When you specify a directory, minifier will recursively traverse all subdirectories and minify .js, .css, and .html files it finds. When you specify a file, only that specific file will be processed.

Options

You can control the minification process using various options. These options are placed after the <path> argument.

Ignoring Files and Directories

Minifier CLI provides flexible ways to ignore specific files or directories from the minification process, similar to .gitignore.

  • Using the --ignore Flag

Use the -i or --ignore flag followed by a comma-separated list of minimatch patterns. You can use this flag multiple times.

  • Ignore a specific file:

    minifier . -i "index.html"
    
  • Ignore a specific directory:

    minifier my_project/ --ignore "images/"
    
  • Ignore all files of a certain type in the current directory (non-recursive):

    minifier . -i "*.map"
    
  • Ignore all files of a certain type recursively:

    minifier . -i "**/*.js"
    

    Note: A single * matches within a single path segment. Use **/*.ext to ignore files recursively across all subdirectories.

  • Ignore multiple patterns:

minifier my_project/ -i "images/,dist/css/"
  • Using an .minifierignore File

You can create a file named .minifierignore in the base directory you are minifying (or specify a custom path) to list patterns of files/directories to ignore. This works just like .gitignore.

  • Example .minifierignore content:

    # Ignore specific files
    dist/index.html
    src/config.js
    # Ignore entire directories
    
    images/
    temp_files/
    
    # Ignore all files of a specific type recursively
    **/*.map
    node_modules/
    
  • Usage with default .minifierignore: Place the .minifierignore file in the same directory as your project root, then run:

    minifier my_project/
    

    or if you're in the project root:

    minifier .
    
  • Using a Custom Ignore File Path

Specify a custom path to your ignore file using the --ignore-path flag:

minifier my_project/ --ignore-path config/.custom_ignore_rules

Note: Patterns provided via the --ignore flag will be combined with patterns found in the .minifierignore file (if present).

Configuration Options Reference

The following table details all available options for customizing the minification process:

Short FlagLong FlagDescriptionDefaultDisable Flag (for defaults that are true)
-V--versionOutput the version number.N/AN/A
-h--helpDisplay help for the command.N/AN/A
-d--drop-consoleDrop console.log statements in JavaScript files.falseN/A
-m--mangleMangle variable and function names in JavaScript files.true--no-mangle
--collapse-whitespaceCollapse whitespace in HTML files.true--no-collapse-whitespace
--remove-commentsRemove comments in HTML files.true--no-remove-comments
--remove-redundant-attributesRemove redundant attributes in HTML files.true--no-remove-redundant-attributes
--use-short-doctypeReplace doctype with short HTML5 doctype ( <!DOCTYPE html>) in HTML files.true--no-use-short-doctype
--minify-cssMinify CSS in <style> tags within HTML files.true--no-minify-css
--minify-jsMinify JavaScript in <script> tags within HTML files.true--no-minify-js
-i--ignore <paths>Comma-separated list of minimatch patterns (files/directories) to ignore. Can be specified multiple times.[]N/A
--ignore-path <file>Path to a custom .minifierignore file. Looks for .minifierignore in the target path's directory by default.N/AN/A
-s--source-mapcreate a source map file for your minified file (css, js) to simplify brower debugingfalseN/A
--source-map-dir <path>Specify where to save your map files, If don't used minifier will save the the map file to where the minified file is saved(Save where minified file is saved)N/A
-o <path>--output-dir <path>Specify an output directory for minified files, relative or absolute. Can include a renaming pattern (e.g., "**/*.min.js").overwriteN/A
--dry-runSimulate minification without writing any files, just to see what files would be minifiedfalseN/A
--no-verboseDisable verbose logging for detailed output.trueN/A

Ignore Patterns Reference

Minifier CLI uses minimatch for pattern matching, which is the same library used by Git.

PatternDescription
foo.txtMatches foo.txt in the base directory.
dir/Matches the directory dir and all its contents (e.g., dir/file.txt, dir/subdir/another.js).
/foo.txtMatches foo.txt only in the base directory, not in subdirectories (e.g., will not match subdir/foo.txt).
*.jsMatches all files ending with .js in the base directory (e.g., app.js), but not in subdirectories (e.g., will not match src/utils.js).
**/*.jsMatches all files ending with .js in the base directory and all its subdirectories (e.g., app.js, src/utils.js, lib/components/button.js). This is the most common pattern for recursive file type ignoring.
foo/**Matches everything inside the foo directory. Equivalent to foo/.
foo/**/bar.jsMatches bar.js in foo/bar.js, foo/baz/bar.js, foo/baz/qux/bar.js, etc.
!patternNegates a pattern. If a file matches a previous ignore pattern but also matches a later negated pattern, it will not be ignored. (e.g., build/, !build/index.html would ignore the build directory except for build/index.html).
# commentLines starting with # in .minifierignore are treated as comments and ignored.
(empty)Empty lines in .minifierignore are ignored.

Examples

  • Minify the entire public directory, drop console.log statements, and keep comments in HTML:

    minifier public/ -d --no-remove-comments
    
  • Minify the current directory, ignore the node_modules and dist folders, and all .map files recursively:

    minifier . -i "node_modules/,dist/,**/*.map"
    
  • Process only index.html and main.js from the build directory, disabling JS mangling and CSS minification within HTML:

    minifier build/index.html build/main.js --no-mangle --no-minify-css
    

    (Note: To process multiple specific files, you would typically run the command for each file or use a script. The minifier <path> argument expects a single file or directory as its primary target.)

  • Minify your src directory using a custom ignore file located at config/my_project.ignore:

    minifier src/ --ignore-path config/my_project.ignore
    
  • Minify all JavaScript files in the current directory, but specifically don't drop console statements:

    minifier . --no-drop-console # Although default, explicitly shows how to negate if it were true
    

    (Note: The --no- prefix only applies to boolean options that default to true.)

    • Minify build directory, dropping console logs and disabling JS variable mangling:
    minifier build --drop-console --no-mangle
    
    • Minify public directory, but keep all comments and whitespace in HTML:
    minifier public --no-remove-comments --no-collapse-whitespace
    

❓ Help & Version

To see the full list of commands and options directly from your terminal: minifier --help

To check the installed version:

minifier --version

🤝 Contributing

Contributions are welcome! If you find a bug or have a feature request, please open an issue on the GitHub repository. Here

📄 License

This project is licensed under the MIT License.

Keywords

minify

FAQs

Package last updated on 12 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts