Skip to content

Repository files navigation


  β–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ•—β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—      β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—
  β–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ•—  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ•β•β–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•”β•β•β•β•β•      β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•β•β•
  β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ•— β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ–ˆβ•”β• β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—
  β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ–ˆβ•”β•  β–ˆβ–ˆβ•”β•β•β•   β•šβ•β•β•β•β–ˆβ–ˆβ•‘β•šβ•β•β•β•β–ˆβ–ˆβ•‘
  β–ˆβ–ˆβ•‘ β•šβ•β• β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β•šβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β•šβ•β• β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—      β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘
  β•šβ•β•     β•šβ•β•β•šβ•β•β•šβ•β•  β•šβ•β•β•β•β•šβ•β•β•šβ•β•     β•šβ•β•β•šβ•β•β•šβ•β•β•β•β•β•β•β•šβ•β•β•β•β•β•β•      β•šβ•β•β•šβ•β•β•β•β•β•β•

Minimize your JS files post-build β€” without creating a bundle.


npm version npm downloads license CI



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 kB

Packages

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 --dev

Usage

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 back

Shebang 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 test

Commits follow Conventional Commits β€” this drives automatic versioning via Lerna.

feat: add new option
fix: handle edge case in shebang detection
chore: update deps

License

MIT β€” Alessandro Casazza


About

Minimize your files without making a bundle

Resources

Stars

8 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages