UglifyJS简介
UglifyJS is a JavaScript compressor/minifier written in JavaScript. It also contains tools that allow one to automate working with JavaScript code:
- 解析器: which produces an abstract syntax tree (AST) from JavaScript code.
- 代码生成器: which outputs JavaScript code from an AST, also providing the option to get a source map.
- 压缩器 (优化器) — it uses the transformer API to optimize an AST into a smaller one.
- 压榨器 — reduce names of local variables to (usually) single-letters.
- 作用域分析器, which is a tool that augments the AST with information about where variables are defined/referenced etc.
- 遍历器 — a simple API allowing you to do something on every node in the AST.
- 转换器 — another API intended to transform the tree.
All the above utilities and APIs are defined in ~6500 lines of code (except for the effective generation of the source-map, which is handled by the source-map module). Compared to alternatives, UglifyJS is pretty small.
These pages document the internals of UglifyJS. For a documentation of the command-line options please see the README.