ββββ βββββββββββ ββββββββββ βββββββββββββββββββββββ βββββββββββ
βββββ βββββββββββββ βββββββββββ ββββββββββββββββββββββββ βββββββββββ
ββββββββββββββββββββ ββββββββββββββββββββ βββββ ββββββ ββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββ βββββ ββββββ ββββββββββββββββ
βββ βββ βββββββββ ββββββββββββ βββ ββββββββββββββββββββββ βββββββββββ
βββ βββββββββ βββββββββββ ββββββββββββββββββββββ βββββββββββ
Minimize your JS files post-build β without creating a bundle.
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 kBThis 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 |
# npm
npm install minimize-js --save-dev
# pnpm
pnpm add minimize-js -D
# yarn
yarn add minimize-js --devminimize-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"
}
}| 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 | β |
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.
your directory
β
βΌ
glob *.js
β
ββββΆ .js files βββΆ esbuild transformSync βββΆ write back
β
ββββΆ .d.ts files βββΆ dts-minify βββΆ write back
Shebang lines (#!/usr/bin/env node) are preserved automatically.
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 deps
MIT β Alessandro Casazza