terser /terser
🗜 JavaScript parser, mangler and compressor toolkit for ES6+
★ 9,357⑂ 494👁 50⑃ 597● 1,181▤ 0
+0
日增长
9,357
stars
494
forks
50
watchers
597
prs
1,181
issues
0
releases
README
[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![CI pipeline][ci-image]][ci-url]
[![Opencollective financial contributors][opencollective-contributors]][opencollective-url]
A JavaScript mangler/compressor toolkit for ES6+.
note: You can support this project on patreon: [link] The Terser Patreon is shutting down in favor of opencollective. Check out PATRONS.md for our first-tier patrons.
Terser recommends you use RollupJS to bundle your modules, as that produces smaller code overall.
Beautification has been undocumented and is being removed from terser, we recommend you use prettier.
Find the changelog in CHANGELOG.md
[npm-image]: https://img.shields.io/npm/v/terser.svg
[npm-url]: https://npmjs.org/package/terser
[downloads-image]: https://img.shields.io/npm/dm/terser.svg
[downloads-url]: https://npmjs.org/package/terser
[ci-image]: https://github.com/terser/terser/actions/workflows/ci.yml/badge.svg
[ci-url]: https://github.com/terser/terser/actions/workflows/ci.yml
[opencollective-contributors]: https://opencollective.com/terser/tiers/badge.svg
[opencollective-url]: https://opencollective.com/terser
Why choose terser?
------------------
uglify-es is no longer maintained and uglify-js does not support ES6+.
terser is a fork of uglify-es that mostly retains API and CLI compatibility
with uglify-es and uglify-js@3.
Install
-------
First make sure you have installed the latest version of node.js
(You may need to restart your computer after this step).
From NPM for use as a command line app:
npm install terser -g
From NPM for programmatic use:
npm install terser
Command line usage
terser [input files] [options]
Terser can take multiple input files. It's recommended that you pass the
input files first, then pass the options. Terser will parse input files
in sequence and apply any compression options. The files are parsed in the
same global scope, that is, a reference from a file to some
variable/function declared in another file will be matched properly.
Command line arguments that take options (like --parse, --compress, --mangle and
--format) can take in a comma-separated list of default option overrides. For
instance:
terser input.js --compress ecma=2015,computed_props=false
If no input file is specified, Terser will read from STDIN.
If you wish to pass your options before the input files, separate the two with
a double dash to prevent input files being used as option arguments:
terser --compress --mangle -- input.js
Command line options
-h, --help Print usage information.
--help options for details on available options.
-V, --version Print version number.
-p, --parse Specify parser options:
acorn Use Acorn for parsing.
bare_returns Allow return outside of functions.
Top issues
#544enable directory terser26 comments · 2020-01-02#513Extend PURE annotations to work on getters as well.22 comments · 2019-11-16#927"v" is redeclared when mangle is enabled17 comments · 2021-02-03#1424Bug: SWC `typeof` helper + terser = SyntaxError on Safari 12.1/12.2/12.313 comments · 2023-08-07#529async functions could be inlined13 comments · 2019-12-05#528pure_funcs calls are not inlined13 comments · 2019-12-05#518quote_style: "AlwaysOriginal" doesn't affect on back quote (`)11 comments · 2019-11-21#1317Increased output size between 5.16.0 and 5.16.110 comments · 2022-12-14