1.0.2 ⢠Published 4 months ago
package-minifier v1.0.2
š 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:
- Use the current working directory as the input folder.
- 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
Step | What Happens |
---|---|
1 | Recursively traverses files in the current working directory |
2 | Minifies JS, CSS, and HTML based on your config options |
3 | Copies other file types unchanged |
4 | Preserves the original folder structure |
5 | Outputs everything into the outputDir directory |
š Options Explained
Option | Type | Description |
---|---|---|
excludeFiles | string[] | List of files to exclude |
excludeFolders | string[] | List of folders to exclude (recursively) |
outputDir | string | Output directory path (relative to current working dir) |
js.enabled | boolean | Enable/disable JS minification/uglification |
js.options | object | Options passed to uglify-js (see docs) |
css.enabled | boolean | Enable/disable CSS minification |
css.options | object | Options passed to clean-css (see docs) |
html.enabled | boolean | Enable/disable HTML minification |
html.options | object | Options 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:
- Fork the repo
- Create a new branch
- Commit your changes
- Submit a PR š
ā License
MIT License Ā© Syed Abdullah