# minify

> Minifier of js, css, html and img

Latest version **15.3.1** (published 2026-04-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install minify
pnpm add minify
yarn add minify
bun add minify
```

Provides the command `minify`.

## Health

**Score 58/100 (C)** — status: active.

Positive: has types package; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 15.3.1 |
| Published | 2026-04-15 |
| First published | 2012-07-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/minify) |
| Module format | ESM + CommonJS |
| Node | >=22 |
| Dependencies | 16 |
| Unpacked size | 39.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 254 |
| Author | coderaiser |
| Maintainers | coderaiser |
| Keywords | minify, minimize, js, css, img, html, base64 |

## Links

- npm: https://www.npmjs.com/package/minify
- Repository: https://github.com/coderaiser/minify
- Homepage: http://coderaiser.github.io/minify
- Issues: https://github.com/coderaiser/minify/issues
- npm.io page: https://npm.io/package/minify

## Dependencies (16)

- [debug](https://npm.io/package/debug.md) ^4.1.0
- [montag](https://npm.io/package/montag.md) ^1.2.1
- [redstd](https://npm.io/package/redstd.md) ^1.0.1
- [terser](https://npm.io/package/terser.md) ^5.28.1
- [esbuild](https://npm.io/package/esbuild.md) ^0.28.0
- [find-up](https://npm.io/package/find-up.md) ^8.0.0
- [readjson](https://npm.io/package/readjson.md) ^2.2.2
- [@swc/core](https://npm.io/package/@swc/core.md) ^1.6.7
- [clean-css](https://npm.io/package/clean-css.md) ^5.0.1
- [try-catch](https://npm.io/package/try-catch.md) ^4.0.7
- [oxc-minify](https://npm.io/package/oxc-minify.md) ^0.125.0
- [lightningcss](https://npm.io/package/lightningcss.md) ^1.28.1
- [try-to-catch](https://npm.io/package/try-to-catch.md) ^4.0.3
- [@putout/minify](https://npm.io/package/@putout/minify.md) ^6.0.0
- [css-b64-images](https://npm.io/package/css-b64-images.md) ~0.2.5
- [html-minifier-next](https://npm.io/package/html-minifier-next.md) ^6.1.2

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 15.3.1 (latest) — 2026-04-15
- 15.3.0 — 2026-04-15
- 15.2.1 — 2026-04-14
- 15.2.0 — 2026-03-04
- 15.1.1 — 2026-03-04
- 15.1.0 — 2026-03-04
- 15.0.1 — 2026-01-11
- 15.0.0 — 2026-01-04
- 14.1.0 — 2025-08-18
- 14.0.0 — 2025-03-24
- 13.0.0 — 2025-02-03
- 12.1.0 — 2025-02-01
- 12.0.1 — 2025-01-13
- 12.0.0 — 2024-11-18
- 11.4.1 — 2024-09-12
- … 161 more at https://npm.io/package/minify/versions

## README

# Minify [![License][LicenseIMGURL]][LicenseURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![NPM version][NPMIMGURL]][NPMURL] [![Coverage Status][CoverageIMGURL]][CoverageURL]

[NPMIMGURL]: https://img.shields.io/npm/v/minify.svg?style=flat
[BuildStatusURL]: https://github.com/coderaiser/minify/actions
[BuildStatusIMGURL]: https://github.com/coderaiser/minify/workflows/CI/badge.svg
[LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat
[NPM_INFO_IMG]: https://nodei.co/npm/minify.png?stars
[NPMURL]: http://npmjs.org/package/minify
[LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License"
[CoverageURL]: https://coveralls.io/github/coderaiser/minify?branch=master
[CoverageIMGURL]: https://coveralls.io/repos/coderaiser/minify/badge.svg?branch=master&service=github

[Minify](http://coderaiser.github.io/minify "Minify") - a minifier of `js`, `css`, `html` and `img` files.

To get things done **Minify** uses these amazing tools:

- ✅ [@putout/minify](https://github.com/putoutjs/minify);
- ✅ [html-minifier-next](https://github.com/j9t/html-minifier-next);
- ✅ [clean-css](https://github.com/jakubpawlowicz/clean-css);
- ✅ [lightningcss](https://lightningcss.dev/);
- ✅ [css-base64-images](https://github.com/Filirom1/css-base64-images);

## Install

For Node users:

```sh
npm i minify -g
```

For Deno users:

```js
import {minify} from 'npm:minify';
```

## How to use?

### CLI

```sh
Usage: minify [options]
Options:
  -h, --help                  display this help and exit
  -v, --version               display version and exit
  --js                        minify javascript
  --css                       minify css
  --html                      minify html
  --auto                      auto detect format
```

The bash command below creates a code snippet saved as `hello.js`.

Simply copy + paste the code starting with cat, including the EOT on the last line, and press <enter>.

```sh
$ cat << EOT > hello.js
const hello = 'world';

for (let i = 0; i < hello.length; i++) {
    console.log(hello[i]);
}
EOT
```

Use the command `minify` followed by the path to and name of the js file intended to be minified. This will minify the code and output it to the screen.

```sh
$ minify hello.js
var a='world';for(let i=0;i<a.length;i++)console.log(a[i]);
```

You can capture the output with the following:

```sh
$ minify hello.js > hello.min.js
```

Use `--fail-on-error` to get a non-zero exit code when minification fails (useful in build scripts and CI):

```sh
$ minify broken.js --fail-on-error > broken.min.js
$ echo $?
1
```

You can pass input using `cat`:

```sh
cat << EOT | bin/minify.js --js
> const hello = 'world';
>
> for (let i = 0; i < hello.length; i++) {
>     console.log(hello[i]);
> }
> EOT
var a='world';for(let i=0;i<a.length;i++)console.log(a[i]);
```

`Minify` can be used with `async-await` and [try-to-catch](https://github.com/coderaiser/try-to-catch):

```js
import {minify} from 'minify';
import {tryToCatch} from 'try-to-catch';

const options = {
    html: {
        removeAttributeQuotes: false,
        removeOptionalTags: false,
    },
};

const [error, data] = await tryToCatch(minify, './client.js', options);

if (error)
    return console.error(error.message);

console.log(data);
```

## Options

For cli use these options can be provided in a JSON file named `.minify.json` like so:

```json
{
    "js": {
        "type": "putout",
        "putout": {
            "quote": "'",
            "mangle": true,
            "mangleClassNames": true,
            "removeUnusedVariables": true,
            "removeConsole": false,
            "removeUselessSpread": true
        }
    },
    "img": {
        "maxSize": 4096
    },
    "html": {
        "removeComments": true,
        "removeCommentsFromCDATA": true,
        "removeCDATASectionsFromCDATA": true,
        "collapseWhitespace": true,
        "collapseBooleanAttributes": true,
        "removeAttributeQuotes": true,
        "removeRedundantAttributes": true,
        "useShortDoctype": true,
        "removeEmptyAttributes": true,
        "removeEmptyElements": false,
        "removeOptionalTags": true,
        "removeScriptTypeAttributes": true,
        "removeStyleLinkTypeAttributes": true,
        "minifyJS": true,
        "minifyCSS": true
    },
    "css": {
        "type": "clean-css",
        "clean-css": {
            "compatibility": "*"
        }
    }
}
```

**Minify** walking up parent directories to locate and read it’s configuration file `.minify.json`.

### `js`

In section related to `js` you can choose `type` of minifier:

- [`putout`](https://github.com/putoutjs/minify#readme); (default);
- [`terser`](https://github.com/terser/terser#minify-options);
- [`esbuild`](https://esbuild.github.io/);
- [`swc`](https://swc.rs/docs/configuration/minification);
- [`oxc`](https://oxc.rs/docs/guide/usage/minifier/dead-code-elimination.html);

When you want to pass [options](https://github.com/terser/terser#minify-options) to `terser`, use section with the same name, `.minify.json` will look this way:

```json
{
    "js": {
        "type": "terser",
        "terser": {
            "mangle": false
        }
    }
}
```

## License

MIT

---
_Source: https://npm.io/package/minify · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
