ConfigsJul 7, 2026·3 min read

UglifyJS — JavaScript Parser, Minifier, and Compressor

A JavaScript toolkit that parses, compresses, and beautifies JavaScript code, reducing file sizes for production deployment through dead code elimination and name mangling.

Agent ready

Ready-to-run agent install

This asset can be installed after the agent chooses its runtime, checks the plan, and runs the matching command.

Native · 98/100Policy: allow
Agent surface
Any MCP/CLI agent
Kind
Skill
Install
Single
Trust
Trust: Established
Entrypoint
UglifyJS Overview
Direct install command
npx -y tokrepo@latest install 8c31f677-7a00-11f1-9bc6-00163e2b0d79 --target codex

Run after dry-run confirms the install plan.

Introduction

UglifyJS is a JavaScript parser, minifier, compressor, and beautifier toolkit. It has been one of the most widely used tools for reducing JavaScript bundle sizes in production, processing code through dead code elimination, constant folding, and variable name mangling to produce smaller output.

What UglifyJS Does

  • Parses JavaScript into a detailed abstract syntax tree
  • Compresses code by applying optimization transforms (dead code removal, inlining, folding)
  • Mangles variable and function names to shorter identifiers
  • Generates source maps for debugging minified code
  • Beautifies code with configurable formatting for readability

Architecture Overview

UglifyJS operates in three phases: parsing source code into an AST, applying a configurable set of compression transforms that simplify and shrink the tree, and generating output code from the optimized AST. Each phase is independent and can be used separately via the API. The compressor applies dozens of passes including conditional folding, dead branch removal, and sequence optimization.

Self-Hosting & Configuration

  • Install as a CLI tool or as a Node.js library for programmatic use
  • Configure compression options via -c flags (drop_console, passes, pure_funcs)
  • Control mangling with -m options (reserved names, property mangling)
  • Integrate with webpack via terser-webpack-plugin (Terser is the ES6+ fork of UglifyJS)
  • Use --source-map to generate maps for production debugging

Key Features

  • Aggressive dead code elimination and tree shaking at the statement level
  • Configurable name mangling with reserved word lists
  • Constant folding and expression simplification
  • Multiple compression passes for incremental optimization
  • Standalone parser usable for code analysis tasks

Comparison with Similar Tools

  • Terser — ES6+-compatible fork of UglifyJS; the recommended successor for modern JavaScript
  • esbuild — Extremely fast Go-based minifier and bundler; less configurable but orders of magnitude faster
  • SWC — Rust-based compiler with built-in minification; fast alternative for large codebases
  • Google Closure Compiler — Whole-program optimization with type-based analysis; produces smaller output but requires type annotations for best results

FAQ

Q: Should I use UglifyJS or Terser? A: Use Terser for new projects. UglifyJS only supports ES5 syntax, while Terser handles ES2015+ natively. Terser started as a fork of uglify-es.

Q: Does UglifyJS support ES6+ syntax? A: UglifyJS 3 targets ES5 only. For ES2015+ code, either transpile with Babel first or switch to Terser, which supports modern syntax directly.

Q: How much size reduction does UglifyJS achieve? A: Typical reductions range from 40% to 70% depending on the code. Compression removes dead code and simplifies expressions, while mangling shortens names further.

Q: Can I use UglifyJS as a library? A: Yes. The Node.js API exposes parse(), compress(), and output() functions, allowing fine-grained control over each phase of the minification pipeline.

Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets