1.0.2 • Published 4 months ago

package-minifier v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

šŸ“‚ Package Minifier

Recursively Minify/Uglify JS, CSS, and HTML Files in a Directory While Preserving Folder Structure!

✨ Features

āœ… Minify/Uglify JavaScript files (with uglify-js)
āœ… Minify CSS files (with clean-css)
āœ… Minify HTML files (with html-minifier-terser)
āœ… Preserve original folder structure
āœ… Highly configurable via package-minifier.config.js or package-minifier.config.ts
āœ… Exclude specific files or folders
āœ… Simple CLI interface
āœ… Works recursively across folders

šŸ“¦ Installation

npm install --save-dev package-minifier

šŸš€ Usage

After installation, you can run it from any directory under your project:

pkgmin

By default, it will:

  1. Use the current working directory as the input folder.
  2. Look for a config file named package-minifier.config.js in the current working directory (or use the default configuration).

šŸ”§ Configuration

Place a file called package-minifier.config.js (or package-minifier.config.ts) in the root of your project directory.

Basic Example (package-minifier.config.js)

import {defineConfig} from "package-minifier";

export default defineConfig({
    excludeFiles: ["ignore.js", "skip-this.html"],
    excludeFolders: ["node_modules", "tests"],
    outputDir: "minified",

    html: {
        enabled: true,
        options: {
            collapseWhitespace: true,
            removeComments: true,
            minifyCSS: true,
            minifyJS: true
        }
    },
    css: {
        enabled: true,
        options: {
            level: 2
        }
    },
    js: {
        enabled: true,
        options: {
            compress: {
                drop_console: true
            },
            mangle: true,
            output: {
                comments: false
            }
        }
    }
});

šŸ“ How It Works

StepWhat Happens
1Recursively traverses files in the current working directory
2Minifies JS, CSS, and HTML based on your config options
3Copies other file types unchanged
4Preserves the original folder structure
5Outputs everything into the outputDir directory

šŸ›  Options Explained

OptionTypeDescription
excludeFilesstring[]List of files to exclude
excludeFoldersstring[]List of folders to exclude (recursively)
outputDirstringOutput directory path (relative to current working dir)
js.enabledbooleanEnable/disable JS minification/uglification
js.optionsobjectOptions passed to uglify-js (see docs)
css.enabledbooleanEnable/disable CSS minification
css.optionsobjectOptions passed to clean-css (see docs)
html.enabledbooleanEnable/disable HTML minification
html.optionsobjectOptions passed to html-minifier-terser (see docs)

āœ… Example Folder Structure

project/
ā”œā”€ā”€ src/
│   ā”œā”€ā”€ index.html
│   ā”œā”€ā”€ style.css
│   └── scripts/
│       └── app.js
ā”œā”€ā”€ package-minifier.config.js
└── minified/    <-- outputDir (generated)

āœ… Contributing

Pull requests are welcome! Here's how to contribute:

  1. Fork the repo
  2. Create a new branch
  3. Commit your changes
  4. Submit a PR šŸš€

āœ… License

MIT License Ā© Syed Abdullah