minimize-js
v1.4.1
Published
Minimize your files without making a bundle
Downloads
2,990
Maintainers
Readme
███╗ ███╗██╗███╗ ██╗██╗███╗ ███╗██╗███████╗███████╗ ██╗███████╗
████╗ ████║██║████╗ ██║██║████╗ ████║██║╚══███╔╝██╔════╝ ██║██╔════╝
██╔████╔██║██║██╔██╗ ██║██║██╔████╔██║██║ ███╔╝ █████╗ ████╗██║███████╗
██║╚██╔╝██║██║██║╚██╗██║██║██║╚██╔╝██║██║ ███╔╝ ██╔══╝ ╚═══╝██║╚════██║
██║ ╚═╝ ██║██║██║ ╚████║██║██║ ╚═╝ ██║██║███████╗███████╗ ██║███████║
╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝╚═╝╚═╝ ╚═╝╚═╝╚══════╝╚══════╝ ╚═╝╚══════╝Minimize your JS files post-build — without creating a bundle.
Overview
minimize-js strips whitespace, rewrites identifiers, and collapses syntax across every file in a directory — powered by esbuild. No bundling, no module graph, no entry points. Just smaller files.
Perfect as a post-build step for libraries that compile TypeScript to CommonJS before publishing.
# Before
dist/index.js → 42 kB
# After
dist/index.js → 18 kBPackages
This project is a monorepo. Two packages, one purpose.
| Package | Description | Install |
|---------|-------------|---------|
| minimize-js | CLI tool | npm i -D minimize-js |
| @minimize-js/core | Programmatic API | npm i @minimize-js/core |
Installation
# npm
npm install minimize-js --save-dev
# pnpm
pnpm add minimize-js -D
# yarn
yarn add minimize-js --devUsage
CLI
minimize-js <directory> [options]Run it on your compiled output directory:
minimize-js lib
minimize-js dist --minifyDeclaration
minimize-js lib --banner "/* Copyright 2024 */"Combine with your build script in package.json:
{
"scripts": {
"build": "tsc -b && minimize-js lib"
}
}Options
| Flag | Alias | Description | Default |
|------|-------|-------------|---------|
| --minifyWhitespace | -w | Remove all whitespace | true |
| --minifyIdentifiers | -i | Shorten variable names | true |
| --minifySyntax | -s | Collapse syntax patterns | true |
| --minifyDeclaration | -d | Minify .d.ts files | false |
| --banner <string> | -b | Prepend a string to each JS file | — |
Programmatic API
Use @minimize-js/core directly in your build scripts or tooling:
import { minimization } from '@minimize-js/core'
const results = minimization(['dist/index.js', 'dist/utils.js'], {
minifyWhitespace: true,
minifyIdentifiers: true,
minifySyntax: true,
minifyDeclaration: false,
banner: '/* my lib v1.0.0 */',
})Returns an array of results — no file I/O, no side effects, fully testable.
How It Works
your directory
│
▼
glob *.js
│
├──▶ .js files ──▶ esbuild transformSync ──▶ write back
│
└──▶ .d.ts files ──▶ dts-minify ──▶ write backShebang lines (#!/usr/bin/env node) are preserved automatically.
Contributing
Contributions are welcome. Fork → branch → PR.
git clone https://github.com/Randagio13/minimize-js
cd minimize-js
pnpm install
pnpm build
pnpm testCommits follow Conventional Commits — this drives automatic versioning via Lerna.
feat: add new option
fix: handle edge case in shebang detection
chore: update depsLicense
MIT — Alessandro Casazza
