Tool:Terser
Appearance
| License | BSD-2-Clause |
|---|---|
| Website | https://github.com/terser/terser |
| On this wiki | Facts · Code · Notes · Topics |
Terser (BSD-2-Clause) is the JavaScript minifier behind most webpack and Vite production bundles: it parses to an AST, compresses with rewrite rules, renames locals and prints compact output.
What it does to code
Three stages, each with its own option object of minify() (README of terser 5.51.2): compress (AST rewrites, on by default), mangle (rename identifiers, on by default) and format/output (printing). Property mangling (mangle.properties) is a separate opt-in pass.
Options that change how output looks
Defaults as stated in the README option list:
sequences(true) joins consecutive simple statements with the comma operator;join_vars(true) merges consecutivevar/let/const.negate_iife(true) negates immediately-called function expressions, giving!function(){...}().booleans,conditionals,if_return,dead_code,evaluate(constant folding),reduce_vars,collapse_vars,inline,hoist_props,unused,properties(dot notation) are all on;passesdefaults to 1.toplevel(false) also drops and renames top-level names;module(false) enables that for ES modules.drop_console(false),drop_debugger(true),pure_funcs,keep_fnames(false),keep_classnames(false) and theunsafe*family (all false).mangleoptions:reserved,toplevel,eval,keep_fnames,keep_classnames,safari10,nth_identifier(default: an internal mangler that weights characters by frequency).mangle.propertiesoptions:builtins(false),keep_quoted,regex,reserved,debug,undeclared.format:comments(default"some": keeps license-style comments),ascii_only,max_line_len,preamble,quote_style,semicolons.
Spotting Terser output
- Whole file on one or few lines, statements chained with commas,
var a=1,b=2runs,!function(){...}()wrappers, short namesa,b,e,t,nassigned by character frequency. - Leading
/*! ... */or@licensecomments are kept. - Terser's source confirms both spellings:
def_optimize(AST_Undefined)returnsmake_void_0(lib/compress/index.js line 2994) anddef_optimize(AST_Boolean)with thebooleansoption (default true) rewrites true and false outside boolean context to!0and!1(lines 3490-3516; commit 707c978227009aa6948f2a1048aa59f5fdd5bc40). Unverified: that esbuild does not produce the same spellings; check against a sample before relying on them to tell it from esbuild. - No Terser banner is added by default; the
preambleoption can add one.
What to do with it
What is renamed and what survives: Technique:JavaScript minifier name mangling. Names come back only with a source map (Format:Source map (v3)). Context: Technique:Reversing bundled JavaScript; the other common minifier is Tool:Esbuild.
Code & repositories
- https://github.com/terser/terser (BSD-2-Clause)
- https://github.com/terser/terser @
707c978227009aa6948f2a1048aa59f5fdd5bc40· license: BSD-2-Clause (declared by the contributor for the files used; GitHub reports BSD-2-Clause (read from LICENSE; GitHub's API was busy) for the repository)
Terser source and README (option reference).
Tested on: source read, not run: source read, not run · checked 2026-10-18