# Terser: JavaScript Minifier and Compressor for ES6+

> Terser is a JavaScript parser, mangler, and compressor that handles ES6 and later syntax. It was forked from uglify-es when that project was abandoned, and it remains the standard command-line and programmatic tool for reducing JavaScript file size in modern build pipelines.

**terser/terser** — 🗜 JavaScript parser, mangler and compressor toolkit for ES6+

- Repository: https://github.com/terser/terser
- Website: https://terser.org
- Stars: 9,344 · Forks: 477
- Language: JavaScript
- License: NOASSERTION
- Published: 2026-09-21 · Updated: 2026-09-21 · Language: en
- Canonical page: https://hysenlabs.com/projects/terser-terser

## Why Terser Exists and Who Uses It

uglify-es, the ES6 fork of uglify-js, was no longer maintained as of the README's writing. uglify-js itself does not support ES6 syntax. Terser was created as a fork of uglify-es to fill that gap, and the README states that it mostly retains API and CLI compatibility with both uglify-es and uglify-js@3.

Terser is used by frontend developers and build tool authors who need to reduce the size of JavaScript files before deploying them. It is the minification engine behind many popular build pipelines, including Webpack's TerserPlugin and Vite's production build. The README notes that RollupJS produces smaller output overall and recommends pairing Terser with Rollup rather than using Terser alone.

The package exports both an ESM entry at `main.js` and a pre-built CommonJS bundle at `dist/bundle.min.js`. TypeScript definitions are at `tools/terser.d.ts`. This means TypeScript projects can import Terser's API with type safety without any additional setup.

## Installing Terser

To install Terser as a command-line tool:

```
npm install terser -g
```

To install it for programmatic use in a project:

```
npm install terser
```

Terser requires Node.js 10 or later. The package ships with the binary at `bin/terser`, a pre-built bundle at `dist/bundle.min.js` for CommonJS consumers, and ESM entry at `main.js`. TypeScript type definitions are included at `tools/terser.d.ts`.

## CLI Compression and Mangling

The basic command-line form takes one or more input files followed by options:

```
terser [input files] [options]
```

To compress a file with specific ECMAScript targets and option overrides:

```
terser input.js --compress ecma=2015,computed_props=false
```

Compression is enabled with `--compress` (`-c`) and mangling with `--mangle` (`-m`). Mangling renames variables to shorter identifiers. To prevent specific names from being mangled:

```
terser ... -m reserved=['$','require','exports']
```

The `--mangle-props` flag renames object property names. The README warns in capital letters that this will break code and recommends restricting it to properties matching a regex pattern:

```
terser example.js -c -m --mangle-props regex=/_$/
```

This only mangles properties ending with an underscore, which is a safe convention for marking internal methods.

When no input file is specified, Terser reads from STDIN, which allows it to be used in shell pipelines. If you need to pass options before the input files, a double dash separates the two:

```
terser --compress --mangle -- input.js
```

The `-p` or `--parse` flag accepts parse options, including `acorn` to use the Acorn parser instead of Terser's built-in parser, and `bare_returns` to allow return statements outside of functions. These are useful when minifying CommonJS modules or userscripts.

## Source Map Support

Terser can generate source maps to make compressed output debuggable. To compress, mangle, and produce a source map:

```
terser js/file1.js js/file2.js \
         -o foo.min.js -c -m \
         --source-map "root='http://foo.com/src',url='foo.min.js.map'"
```

This writes the compressed output to `foo.min.js` and the source map to `foo.min.js.map`. The source map references `http://foo.com/src/js/file1.js` and `http://foo.com/src/js/file2.js` as originals.

Composed source maps are also supported. When the input JavaScript was already compiled from another language (for example CoffeeScript), passing `--source-map "content='/path/to/input/source.map'"` tells Terser to chain the two maps, producing a map from the original source to the compressed output. If the input source map is inline, `content=inline` reads it from the file.

The `--output` (`-o`) flag specifies the output file; without it, the compressed output goes to STDOUT.

## Limitations and Removed Features

The README states that beautification (pretty-printing) is undocumented and is being removed from Terser. The recommendation is to use Prettier for code formatting instead. Projects that rely on Terser's `--beautify` flag should plan to migrate.

Terser's property mangling is powerful but dangerous outside of controlled use. The README warns explicitly: "THIS WILL BREAK YOUR CODE" when using `--mangle-props` without a regex restriction. Any property name used in external-facing APIs, library interfaces, or JSON serialization cannot be safely mangled without thorough testing.

Terser also does not bundle modules. It compresses and mangles single files or multiple files parsed in the same scope. For tree shaking and module bundling, a tool like RollupJS should run before Terser.

The `--mangle` flag renames variables in the top level scope only when `toplevel` is explicitly set to true. By default, top-level names are not mangled. This is a deliberate safety default: many JavaScript files export global names that other scripts depend on, and mangling them would break those consumers. The `eval` sub-option for mangling names visible in `eval` scopes is also off by default, because Terser cannot reliably determine which names an eval expression will access at runtime.

## Comparison with esbuild and Maintenance Status

esbuild is the most commonly cited alternative to Terser for JavaScript minification. The key difference is build speed: esbuild is written in Go and compiles and minifies significantly faster than Terser for large codebases. However, esbuild's minification produces slightly different output in some cases, and some build pipelines specifically configure Terser for output quality reasons.

Terser retains the uglify-js API surface, which means projects that previously used uglify-js or uglify-es can switch with minimal code changes. esbuild has a different API.

The project version is 5.51.2 as shown in `package.json`. The last push was on 2026-09-24. Terser is licensed under BSD-2-Clause and maintained by Fabio Santos, listed in the package.json `maintainers` field.

The RECIPES.md file in the repository suggests that the team documents common patterns for using Terser in specific build scenarios. The repository also includes a SECURITY.md, indicating a process for reporting vulnerabilities. The `overrides` field in `package.json` pins `serialize-javascript` to 6.0.2 and `js-yaml` to 4.2.0, both of which are transitive dependency upgrades applied for security reasons.

The CHANGELOG.md tracks the history of changes across versions. The `renovate.json` configuration automates dependency update pull requests, and the `overrides` block in `package.json` pins transitive dependencies at security-relevant versions. These are signs of an actively governed project, not one that only accepts patches when users report them. The SECURITY.md file documents the process for reporting vulnerabilities, and a PATRONS.md file acknowledges financial contributors through OpenCollective. Terser's funding moved from Patreon to OpenCollective, as the README states directly; the Patreon is shutting down in favor of OpenCollective. The project also includes a RECIPES.md file with documented patterns for common minification scenarios.

## Conclusion

Terser is the right tool for teams that need a reliable, standalone JavaScript minifier with ES6+ support, source map generation, and a familiar uglify-js-compatible API. It is not a bundler; the README recommends using RollupJS for module bundling and treating Terser as the minification step that runs after bundling. The property mangling feature is explicitly flagged in the README as likely to break code and should be used only with the `regex` option scoped to internal identifiers. The BSD-2-Clause license applies to the package itself; the actual license entry in the repository metadata reads NOASSERTION, but the package.json states BSD-2-Clause.

## FAQ

### What is Terser?

Terser is a JavaScript parser, mangler, and compressor for ES6 and later syntax. It is a fork of uglify-es, which is no longer maintained, and retains API and CLI compatibility with uglify-es and uglify-js@3.

### How do I install Terser?

Install Terser globally with npm install terser -g for the CLI, or npm install terser for programmatic use in a project. Node.js 10 or later is required.

### How do I use Terser to compress a JavaScript file?

Run terser input.js --compress --mangle --output output.min.js. Pass --compress (-c) to enable compression and --mangle (-m) to rename variables to shorter names. Specific options such as ecma=2015 are passed as comma-separated key=value pairs after --compress.

### What does Terser do differently from UglifyJS?

Terser supports ES6 and later syntax, which uglify-js does not. It was forked from uglify-es after that project was abandoned, and it retains API and CLI compatibility with both uglify-es and uglify-js@3.

### What does Terser do in a build pipeline?

Terser compresses and mangles JavaScript files to reduce their size for production deployment. It parses input files, applies compression optimizations such as removing dead code and collapsing constant expressions, and renames variables to shorter identifiers. The README recommends using RollupJS to bundle modules first and then running Terser on the output.

## Sources

- [Issues](https://github.com/terser/terser/issues)
- [Project website](https://terser.org)
- [README](https://github.com/terser/terser/blob/master/README.md)
- [terser/terser on GitHub](https://github.com/terser/terser)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/terser-terser
