Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 30 additions & 17 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,50 @@
name: Release
name: CI

on:
push:
branches: [main, beta, alpha]
pull_request:
branches: [main, beta, alpha]

jobs:
release:
name: Release
ci:
name: CI
runs-on: ubuntu-latest

steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: pnpm 🧰
uses: pnpm/action-setup@v2.2.2
- name: pnpm
uses: pnpm/action-setup@v4
with:
version: 7
version: 9

- name: Node 🧰
uses: actions/setup-node@v3
- name: Node
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: 'pnpm'
cache: pnpm
registry-url: https://registry.npmjs.org

- name: Install 📦
run: pnpm install --no-frozen-lockfile
- name: Install
run: pnpm install --frozen-lockfile

- name: Build 🛠
- name: Lint
run: pnpm exec biome check .

- name: Build
run: pnpm build

- name: Test
run: pnpm test --coverage

- name: Release
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: pnpm dlx semantic-release
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: pnpm lerna version --conventional-commits --yes && pnpm lerna publish from-git --yes
176 changes: 136 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,81 +1,177 @@
<div align="center">

# Minimize JS
<br />

```
███╗ ███╗██╗███╗ ██╗██╗███╗ ███╗██╗███████╗███████╗ ██╗███████╗
████╗ ████║██║████╗ ██║██║████╗ ████║██║╚══███╔╝██╔════╝ ██║██╔════╝
██╔████╔██║██║██╔██╗ ██║██║██╔████╔██║██║ ███╔╝ █████╗ ████╗██║███████╗
██║╚██╔╝██║██║██║╚██╗██║██║██║╚██╔╝██║██║ ███╔╝ ██╔══╝ ╚═══╝██║╚════██║
██║ ╚═╝ ██║██║██║ ╚████║██║██║ ╚═╝ ██║██║███████╗███████╗ ██║███████║
╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝╚═╝╚═╝ ╚═╝╚═╝╚══════╝╚══════╝ ╚═╝╚══════╝
```

**Minimize your JS files post-build — without creating a bundle.**

<br />

### Minimize your files without making a bundle
[![npm version](https://img.shields.io/npm/v/minimize-js?style=flat-square&color=000&labelColor=000&logo=npm&logoColor=fff)](https://www.npmjs.com/package/minimize-js)
[![npm downloads](https://img.shields.io/npm/dt/minimize-js?style=flat-square&color=000&labelColor=000)](https://www.npmjs.com/package/minimize-js)
[![license](https://img.shields.io/npm/l/minimize-js?style=flat-square&color=000&labelColor=000)](LICENSE)
[![CI](https://img.shields.io/github/actions/workflow/status/Randagio13/minimize-js/main.yml?style=flat-square&color=000&labelColor=000&label=CI)](https://github.com/Randagio13/minimize-js/actions)

[![NPM](https://nodei.co/npm/minimize-js.png?compact=true)](https://nodei.co/npm/minimize-js/)
<br />
[![](https://img.shields.io/npm/dt/minimize-js.svg?style=flat-square)](https://www.npmjs.com/package/minimize-js)

</div>

## Table of contents
---

## Overview

`minimize-js` strips whitespace, rewrites identifiers, and collapses syntax across every file in a directory — powered by [esbuild](https://esbuild.github.io/). No bundling, no module graph, no entry points. Just smaller files.

1. [Getting started](#getting-started)
- [Installation](#installation)
- [Options](#options)
2. [Usage](#usage)
3. [Contributors](#contributors)
4. [Need help](#need-help)
5. [License](#license)
6. [Sponsor](#sponsor)
Perfect as a **post-build step** for libraries that compile TypeScript to CommonJS before publishing.

```bash
# Before
dist/index.js → 42 kB
# After
dist/index.js → 18 kB
```

## Getting started
---

To get started with this library, you need to install it and add it to your project.
## Packages

### Installation
This project is a monorepo. Two packages, one purpose.

Minimize JS is available as an npm package.
| Package | Description | Install |
|---------|-------------|---------|
| [`minimize-js`](./packages/cli) | CLI tool | `npm i -D minimize-js` |
| [`@minimize-js/core`](./packages/core) | Programmatic API | `npm i @minimize-js/core` |

---

## Installation

```bash
# npm
npm install minimize-js -D
npm install minimize-js --save-dev

# pnpm
pnpm add minimize-js -D

# yarn
yarn add minimize-js -D
yarn add minimize-js --dev
```

### Options
---

## Usage

### CLI

```bash
-w --minifyWhitespace It only removes whitespace characters #default: true
-i --minifyIdentifiers It only transforms the identifiers #default: true
-s --minifySyntax It only transforms the syntax #default: true
-d --minifyDeclaration It only removes whitespace characters within .d.ts files #default: false
minimize-js <directory> [options]
```

## Usage

The code snippet below shows how to put into action `minimize-js` and lets you minimize your files inside a directory.
Run it on your compiled output directory:

```bash
minimize-js <directory> -<option> --<option>
minimize-js lib
minimize-js dist --minifyDeclaration
minimize-js lib --banner "/* Copyright 2024 */"
```

Combine with your build script in `package.json`:

```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:

```typescript
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 */',
})
```

## Contributors
Returns an array of results — no file I/O, no side effects, fully testable.

Any contribution is appreciated. You can get started with the steps below:
---

1. Fork [this repository](https://github.com/Randagio13/minimize-js) (learn how to do this [here](https://help.github.com/articles/fork-a-repo)).
## How It Works

2. Clone the forked repository.
```
your directory
glob *.js
├──▶ .js files ──▶ esbuild transformSync ──▶ write back
└──▶ .d.ts files ──▶ dts-minify ──▶ write back
```

3. Make your changes and create a pull request ([learn how to do this](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request)).
Shebang lines (`#!/usr/bin/env node`) are preserved automatically.

4. I will attend to your pull request and provide some feedback.
---

## Need help?
## Contributing

Ping me [on Twitter](https://twitter.com/randagio19)
Contributions are welcome. Fork → branch → PR.

```bash
git clone https://github.com/Randagio13/minimize-js
cd minimize-js
pnpm install
pnpm build
pnpm test
```

Commits follow [Conventional Commits](https://www.conventionalcommits.org/) — this drives automatic versioning via Lerna.

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

---

## License

This repository is licensed under the [MIT](LICENSE) License.
[MIT](LICENSE) — Alessandro Casazza

## Sponsor
---

Don't be shy! 😜
<div align="center">

[:heart: Sponsor](https://github.com/sponsors/Randagio13)
[:heart: Sponsor this project](https://github.com/sponsors/Randagio13)

</div>
10 changes: 5 additions & 5 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
presets: [
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-typescript',
],
}
presets: [
["@babel/preset-env", { targets: { node: "current" } }],
"@babel/preset-typescript",
],
};
34 changes: 34 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"$schema": "https://biomejs.dev/schemas/2.4.12/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"files": {
"ignoreUnknown": false
},
"formatter": {
"enabled": true,
"indentStyle": "tab"
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"javascript": {
"formatter": {
"quoteStyle": "double"
}
},
"assist": {
"enabled": true,
"actions": {
"source": {
"organizeImports": "on"
}
}
}
}
Loading
Loading