41e7ee8e68b4faf81dac55bba5f253cbec28ee9d7f5089c3393ac7c27cebdade2f07a141c2b3945b9ab4eea463d6ed76779529e91947bebc6859ea6bc47b9b 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175
  1. uglify-es
  2. =========
  3. A JavaScript parser, mangler/compressor and beautifier toolkit for ES6+.
  4. #### Note:
  5. - **`uglify-es` is API/CLI compatible with `uglify-js@3`.**
  6. - **`uglify-es` is not backwards compatible with `uglify-js@2`.**
  7. Install
  8. -------
  9. First make sure you have installed the latest version of [node.js](http://nodejs.org/)
  10. (You may need to restart your computer after this step).
  11. From NPM for use as a command line app:
  12. npm install uglify-es -g
  13. From NPM for programmatic use:
  14. npm install uglify-es
  15. # Command line usage
  16. uglifyjs [input files] [options]
  17. UglifyJS can take multiple input files. It's recommended that you pass the
  18. input files first, then pass the options. UglifyJS will parse input files
  19. in sequence and apply any compression options. The files are parsed in the
  20. same global scope, that is, a reference from a file to some
  21. variable/function declared in another file will be matched properly.
  22. If no input file is specified, UglifyJS will read from STDIN.
  23. If you wish to pass your options before the input files, separate the two with
  24. a double dash to prevent input files being used as option arguments:
  25. uglifyjs --compress --mangle -- input.js
  26. ### Command line options
  27. ```
  28. -h, --help Print usage information.
  29. `--help options` for details on available options.
  30. -V, --version Print version number.
  31. -p, --parse <options> Specify parser options:
  32. `acorn` Use Acorn for parsing.
  33. `bare_returns` Allow return outside of functions.
  34. Useful when minifying CommonJS
  35. modules and Userscripts that may
  36. be anonymous function wrapped (IIFE)
  37. by the .user.js engine `caller`.
  38. `expression` Parse a single expression, rather than
  39. a program (for parsing JSON).
  40. `spidermonkey` Assume input files are SpiderMonkey
  41. AST format (as JSON).
  42. -c, --compress [options] Enable compressor/specify compressor options:
  43. `pure_funcs` List of functions that can be safely
  44. removed when their return values are
  45. not used.
  46. -m, --mangle [options] Mangle names/specify mangler options:
  47. `reserved` List of names that should not be mangled.
  48. --mangle-props [options] Mangle properties/specify mangler options:
  49. `builtins` Mangle property names that overlaps
  50. with standard JavaScript globals.
  51. `debug` Add debug prefix and suffix.
  52. `domprops` Mangle property names that overlaps
  53. with DOM properties.
  54. `keep_quoted` Only mangle unquoted properties.
  55. `regex` Only mangle matched property names.
  56. `reserved` List of names that should not be mangled.
  57. -b, --beautify [options] Beautify output/specify output options:
  58. `beautify` Enabled with `--beautify` by default.
  59. `preamble` Preamble to prepend to the output. You
  60. can use this to insert a comment, for
  61. example for licensing information.
  62. This will not be parsed, but the source
  63. map will adjust for its presence.
  64. `quote_style` Quote style:
  65. 0 - auto
  66. 1 - single
  67. 2 - double
  68. 3 - original
  69. `wrap_iife` Wrap IIFEs in parenthesis. Note: you may
  70. want to disable `negate_iife` under
  71. compressor options.
  72. -o, --output <file> Output file path (default STDOUT). Specify `ast` or
  73. `spidermonkey` to write UglifyJS or SpiderMonkey AST
  74. as JSON to STDOUT respectively.
  75. --comments [filter] Preserve copyright comments in the output. By
  76. default this works like Google Closure, keeping
  77. JSDoc-style comments that contain "@license" or
  78. "@preserve". You can optionally pass one of the
  79. following arguments to this flag:
  80. - "all" to keep all comments
  81. - a valid JS RegExp like `/foo/` or `/^!/` to
  82. keep only matching comments.
  83. Note that currently not *all* comments can be
  84. kept when compression is on, because of dead
  85. code removal or cascading statements into
  86. sequences.
  87. --config-file <file> Read `minify()` options from JSON file.
  88. -d, --define <expr>[=value] Global definitions.
  89. --ecma <version> Specify ECMAScript release: 5, 6, 7 or 8.
  90. --ie8 Support non-standard Internet Explorer 8.
  91. Equivalent to setting `ie8: true` in `minify()`
  92. for `compress`, `mangle` and `output` options.
  93. By default UglifyJS will not try to be IE-proof.
  94. --keep-classnames Do not mangle/drop class names.
  95. --keep-fnames Do not mangle/drop function names. Useful for
  96. code relying on Function.prototype.name.
  97. --name-cache <file> File to hold mangled name mappings.
  98. --safari10 Support non-standard Safari 10/11.
  99. Equivalent to setting `safari10: true` in `minify()`
  100. for `mangle` and `output` options.
  101. By default `uglify-es` will not work around
  102. Safari 10/11 bugs.
  103. --self Build UglifyJS as a library (implies --wrap UglifyJS)
  104. --source-map [options] Enable source map/specify source map options:
  105. `base` Path to compute relative paths from input files.
  106. `content` Input source map, useful if you're compressing
  107. JS that was generated from some other original
  108. code. Specify "inline" if the source map is
  109. included within the sources.
  110. `filename` Name and/or location of the output source.
  111. `includeSources` Pass this flag if you want to include
  112. the content of source files in the
  113. source map as sourcesContent property.
  114. `root` Path to the original source to be included in
  115. the source map.
  116. `url` If specified, path to the source map to append in
  117. `//# sourceMappingURL`.
  118. --timings Display operations run time on STDERR.
  119. --toplevel Compress and/or mangle variables in top level scope.
  120. --verbose Print diagnostic messages.
  121. --warn Print warning messages.
  122. --wrap <name> Embed everything in a big function, making the
  123. “exports” and “global” variables available. You
  124. need to pass an argument to this option to
  125. specify the name that your module will take
  126. when included in, say, a browser.
  127. ```
  128. Specify `--output` (`-o`) to declare the output file. Otherwise the output
  129. goes to STDOUT.
  130. ## CLI source map options
  131. UglifyJS can generate a source map file, which is highly useful for
  132. debugging your compressed JavaScript. To get a source map, pass
  133. `--source-map --output output.js` (source map will be written out to
  134. `output.js.map`).
  135. Additional options:
  136. - `--source-map "filename='<NAME>'"` to specify the name of the source map.
  137. - `--source-map "root='<URL>'"` to pass the URL where the original files can be found.
  138. - `--source-map "url='<URL>'"` to specify the URL where the source map can be found.
  139. Otherwise UglifyJS assumes HTTP `X-SourceMap` is being used and will omit the
  140. `//# sourceMappingURL=` directive.
  141. For example:
  142. uglifyjs js/file1.js js/file2.js \
  143. -o foo.min.js -c -m \
  144. --source-map "root='http://foo.com/src',url='foo.min.js.map'"
  145. The above will compress and mangle `file1.js` and `file2.js`, will drop the
  146. output in `foo.min.js` and the source map in `foo.min.js.map`. The source
  147. mapping will refer to `http://foo.com/src/js/file1.js` and
  148. `http://foo.com/src/js/file2.js` (in fact it will list `http://foo.com/src`
  149. as the source map root, and the original files as `js/file1.js` and
  150. `js/file2.js`).
  151. ### Composed source map
  152. When you're compressing JS code that was output by a compiler such as
  153. CoffeeScript, mapping to the JS code won't be too helpful. Instead, you'd
  154. like to map back to the original code (i.e. CoffeeScript). UglifyJS has an
  155. option to take an input source map. Assuming you have a mapping from
  156. CoffeeScript → compiled JS, UglifyJS can generate a map from CoffeeScript →
  157. compressed JS by mapping every token in the compiled JS to its original
  158. location.
  159. To use this feature pass `--source-map "content='/path/to/input/source.map'"`
  160. or `--source-map "content=inline"` if the source map is included inline with
  161. the sources.
  162. ## CLI compress options
  163. You need to pass `--compress` (`-c`) to enable the compressor. Optionally
  164. you can pass a comma-separated list of [compress options](#compress-options).
  165. Options are in the form `foo=bar`, or just `foo` (the latter implies
  166. a boolean option that you want to set `true`; it's effectively a
  167. shortcut for `foo=true`).
  168. Example:
  169. uglifyjs file.js -c toplevel,sequences=false
  170. ## CLI mangle options
  171. To enable the mangler you need to pass `--mangle` (`-m`). The following
  172. (comma-separated) options are supported:
  173. - `toplevel` (default `false`) -- mangle names declared in the top level scope.
  174. - `eval` (default `false`) -- mangle names visible in scopes where `eval` or `with` are used.
  175. When mangling is enabled but you want to prevent certain names from being
  176. mangled, you can declare those names with `--mangle reserved` — pass a
  177. comma-separated list of names. For example:
  178. uglifyjs ... -m reserved=['$','require','exports']
  179. to prevent the `require`, `exports` and `$` names from being changed.
  180. ### CLI mangling property names (`--mangle-props`)
  181. **Note:** THIS WILL PROBABLY BREAK YOUR CODE. Mangling property names
  182. is a separate step, different from variable name mangling. Pass
  183. `--mangle-props` to enable it. It will mangle all properties in the
  184. input code with the exception of built in DOM properties and properties
  185. in core JavaScript classes. For example:
  186. ```javascript
  187. // example.js
  188. var x = {
  189. baz_: 0,
  190. foo_: 1,
  191. calc: function() {
  192. return this.foo_ + this.baz_;
  193. }
  194. };
  195. x.bar_ = 2;
  196. x["baz_"] = 3;
  197. console.log(x.calc());
  198. ```
  199. Mangle all properties (except for JavaScript `builtins`):
  200. ```bash
  201. $ uglifyjs example.js -c -m --mangle-props
  202. ```
  203. ```javascript
  204. var x={o:0,_:1,l:function(){return this._+this.o}};x.t=2,x.o=3,console.log(x.l());
  205. ```
  206. Mangle all properties except for `reserved` properties:
  207. ```bash
  208. $ uglifyjs example.js -c -m --mangle-props reserved=[foo_,bar_]
  209. ```
  210. ```javascript
  211. var x={o:0,foo_:1,_:function(){return this.foo_+this.o}};x.bar_=2,x.o=3,console.log(x._());
  212. ```
  213. Mangle all properties matching a `regex`:
  214. ```bash
  215. $ uglifyjs example.js -c -m --mangle-props regex=/_$/
  216. ```
  217. ```javascript
  218. var x={o:0,_:1,calc:function(){return this._+this.o}};x.l=2,x.o=3,console.log(x.calc());
  219. ```
  220. Combining mangle properties options:
  221. ```bash
  222. $ uglifyjs example.js -c -m --mangle-props regex=/_$/,reserved=[bar_]
  223. ```
  224. ```javascript
  225. var x={o:0,_:1,calc:function(){return this._+this.o}};x.bar_=2,x.o=3,console.log(x.calc());
  226. ```
  227. In order for this to be of any use, we avoid mangling standard JS names by
  228. default (`--mangle-props builtins` to override).
  229. A default exclusion file is provided in `tools/domprops.json` which should
  230. cover most standard JS and DOM properties defined in various browsers. Pass
  231. `--mangle-props domprops` to disable this feature.
  232. A regular expression can be used to define which property names should be
  233. mangled. For example, `--mangle-props regex=/^_/` will only mangle property
  234. names that start with an underscore.
  235. When you compress multiple files using this option, in order for them to
  236. work together in the end we need to ensure somehow that one property gets
  237. mangled to the same name in all of them. For this, pass `--name-cache filename.json`
  238. and UglifyJS will maintain these mappings in a file which can then be reused.
  239. It should be initially empty. Example:
  240. ```bash
  241. $ rm -f /tmp/cache.json # start fresh
  242. $ uglifyjs file1.js file2.js --mangle-props --name-cache /tmp/cache.json -o part1.js
  243. $ uglifyjs file3.js file4.js --mangle-props --name-cache /tmp/cache.json -o part2.js
  244. ```
  245. Now, `part1.js` and `part2.js` will be consistent with each other in terms
  246. of mangled property names.
  247. Using the name cache is not necessary if you compress all your files in a
  248. single call to UglifyJS.
  249. ### Mangling unquoted names (`--mangle-props keep_quoted`)
  250. Using quoted property name (`o["foo"]`) reserves the property name (`foo`)
  251. so that it is not mangled throughout the entire script even when used in an
  252. unquoted style (`o.foo`). Example:
  253. ```javascript
  254. // stuff.js
  255. var o = {
  256. "foo": 1,
  257. bar: 3
  258. };
  259. o.foo += o.bar;
  260. console.log(o.foo);
  261. ```
  262. ```bash
  263. $ uglifyjs stuff.js --mangle-props keep_quoted -c -m
  264. ```
  265. ```javascript
  266. var o={foo:1,o:3};o.foo+=o.o,console.log(o.foo);
  267. ```
  268. ### Debugging property name mangling
  269. You can also pass `--mangle-props debug` in order to mangle property names
  270. without completely obscuring them. For example the property `o.foo`
  271. would mangle to `o._$foo$_` with this option. This allows property mangling
  272. of a large codebase while still being able to debug the code and identify
  273. where mangling is breaking things.
  274. ```bash
  275. $ uglifyjs stuff.js --mangle-props debug -c -m
  276. ```
  277. ```javascript
  278. var o={_$foo$_:1,_$bar$_:3};o._$foo$_+=o._$bar$_,console.log(o._$foo$_);
  279. ```
  280. You can also pass a custom suffix using `--mangle-props debug=XYZ`. This would then
  281. mangle `o.foo` to `o._$foo$XYZ_`. You can change this each time you compile a
  282. script to identify how a property got mangled. One technique is to pass a
  283. random number on every compile to simulate mangling changing with different
  284. inputs (e.g. as you update the input script with new properties), and to help
  285. identify mistakes like writing mangled keys to storage.
  286. # API Reference
  287. Assuming installation via NPM, you can load UglifyJS in your application
  288. like this:
  289. ```javascript
  290. var UglifyJS = require("uglify-es");
  291. ```
  292. There is a single high level function, **`minify(code, options)`**,
  293. which will perform all minification [phases](#minify-options) in a configurable
  294. manner. By default `minify()` will enable the options [`compress`](#compress-options)
  295. and [`mangle`](#mangle-options). Example:
  296. ```javascript
  297. var code = "function add(first, second) { return first + second; }";
  298. var result = UglifyJS.minify(code);
  299. console.log(result.error); // runtime error, or `undefined` if no error
  300. console.log(result.code); // minified output: function add(n,d){return n+d}
  301. ```
  302. You can `minify` more than one JavaScript file at a time by using an object
  303. for the first argument where the keys are file names and the values are source
  304. code:
  305. ```javascript
  306. var code = {
  307. "file1.js": "function add(first, second) { return first + second; }",
  308. "file2.js": "console.log(add(1 + 2, 3 + 4));"
  309. };
  310. var result = UglifyJS.minify(code);
  311. console.log(result.code);
  312. // function add(d,n){return d+n}console.log(add(3,7));
  313. ```
  314. The `toplevel` option:
  315. ```javascript
  316. var code = {
  317. "file1.js": "function add(first, second) { return first + second; }",
  318. "file2.js": "console.log(add(1 + 2, 3 + 4));"
  319. };
  320. var options = { toplevel: true };
  321. var result = UglifyJS.minify(code, options);
  322. console.log(result.code);
  323. // console.log(3+7);
  324. ```
  325. The `nameCache` option:
  326. ```javascript
  327. var options = {
  328. mangle: {
  329. toplevel: true,
  330. },
  331. nameCache: {}
  332. };
  333. var result1 = UglifyJS.minify({
  334. "file1.js": "function add(first, second) { return first + second; }"
  335. }, options);
  336. var result2 = UglifyJS.minify({
  337. "file2.js": "console.log(add(1 + 2, 3 + 4));"
  338. }, options);
  339. console.log(result1.code);
  340. // function n(n,r){return n+r}
  341. console.log(result2.code);
  342. // console.log(n(3,7));
  343. ```
  344. You may persist the name cache to the file system in the following way:
  345. ```javascript
  346. var cacheFileName = "/tmp/cache.json";
  347. var options = {
  348. mangle: {
  349. properties: true,
  350. },
  351. nameCache: JSON.parse(fs.readFileSync(cacheFileName, "utf8"))
  352. };
  353. fs.writeFileSync("part1.js", UglifyJS.minify({
  354. "file1.js": fs.readFileSync("file1.js", "utf8"),
  355. "file2.js": fs.readFileSync("file2.js", "utf8")
  356. }, options).code, "utf8");
  357. fs.writeFileSync("part2.js", UglifyJS.minify({
  358. "file3.js": fs.readFileSync("file3.js", "utf8"),
  359. "file4.js": fs.readFileSync("file4.js", "utf8")
  360. }, options).code, "utf8");
  361. fs.writeFileSync(cacheFileName, JSON.stringify(options.nameCache), "utf8");
  362. ```
  363. An example of a combination of `minify()` options:
  364. ```javascript
  365. var code = {
  366. "file1.js": "function add(first, second) { return first + second; }",
  367. "file2.js": "console.log(add(1 + 2, 3 + 4));"
  368. };
  369. var options = {
  370. toplevel: true,
  371. compress: {
  372. global_defs: {
  373. "@console.log": "alert"
  374. },
  375. passes: 2
  376. },
  377. output: {
  378. beautify: false,
  379. preamble: "/* uglified */"
  380. }
  381. };
  382. var result = UglifyJS.minify(code, options);
  383. console.log(result.code);
  384. // /* uglified */
  385. // alert(10);"
  386. ```
  387. To produce warnings:
  388. ```javascript
  389. var code = "function f(){ var u; return 2 + 3; }";
  390. var options = { warnings: true };
  391. var result = UglifyJS.minify(code, options);
  392. console.log(result.error); // runtime error, `undefined` in this case
  393. console.log(result.warnings); // [ 'Dropping unused variable u [0:1,18]' ]
  394. console.log(result.code); // function f(){return 5}
  395. ```
  396. An error example:
  397. ```javascript
  398. var result = UglifyJS.minify({"foo.js" : "if (0) else console.log(1);"});
  399. console.log(JSON.stringify(result.error));
  400. // {"message":"Unexpected token: keyword (else)","filename":"foo.js","line":1,"col":7,"pos":7}
  401. ```
  402. Note: unlike `uglify-js@2.x`, the `3.x` API does not throw errors. To
  403. achieve a similar effect one could do the following:
  404. ```javascript
  405. var result = UglifyJS.minify(code, options);
  406. if (result.error) throw result.error;
  407. ```
  408. ## Minify options
  409. - `ecma` (default `undefined`) - pass `5`, `6`, `7` or `8` to override `parse`,
  410. `compress` and `output` options.
  411. - `warnings` (default `false`) — pass `true` to return compressor warnings
  412. in `result.warnings`. Use the value `"verbose"` for more detailed warnings.
  413. - `parse` (default `{}`) — pass an object if you wish to specify some
  414. additional [parse options](#parse-options).
  415. - `compress` (default `{}`) — pass `false` to skip compressing entirely.
  416. Pass an object to specify custom [compress options](#compress-options).
  417. - `mangle` (default `true`) — pass `false` to skip mangling names, or pass
  418. an object to specify [mangle options](#mangle-options) (see below).
  419. - `mangle.properties` (default `false`) — a subcategory of the mangle option.
  420. Pass an object to specify custom [mangle property options](#mangle-properties-options).
  421. - `output` (default `null`) — pass an object if you wish to specify
  422. additional [output options](#output-options). The defaults are optimized
  423. for best compression.
  424. - `sourceMap` (default `false`) - pass an object if you wish to specify
  425. [source map options](#source-map-options).
  426. - `toplevel` (default `false`) - set to `true` if you wish to enable top level
  427. variable and function name mangling and to drop unused variables and functions.
  428. - `nameCache` (default `null`) - pass an empty object `{}` or a previously
  429. used `nameCache` object if you wish to cache mangled variable and
  430. property names across multiple invocations of `minify()`. Note: this is
  431. a read/write property. `minify()` will read the name cache state of this
  432. object and update it during minification so that it may be
  433. reused or externally persisted by the user.
  434. - `ie8` (default `false`) - set to `true` to support IE8.
  435. - `keep_classnames` (default: `undefined`) - pass `true` to prevent discarding or mangling
  436. of class names.
  437. - `keep_fnames` (default: `false`) - pass `true` to prevent discarding or mangling
  438. of function names. Useful for code relying on `Function.prototype.name`. If the
  439. top level minify option `keep_classnames` is `undefined` it will be overriden with
  440. the value of the top level minify option `keep_fnames`.
  441. - `safari10` (default: `false`) - pass `true` to work around Safari 10/11 bugs in
  442. loop scoping and `await`. See `safari10` options in [`mangle`](#mangle-options)
  443. and [`output`](#output-options) for details.
  444. ## Minify options structure
  445. ```javascript
  446. {
  447. parse: {
  448. // parse options
  449. },
  450. compress: {
  451. // compress options
  452. },
  453. mangle: {
  454. // mangle options
  455. properties: {
  456. // mangle property options
  457. }
  458. },
  459. output: {
  460. // output options
  461. },
  462. sourceMap: {
  463. // source map options
  464. },
  465. ecma: 5, // specify one of: 5, 6, 7 or 8
  466. keep_classnames: false,
  467. keep_fnames: false,
  468. ie8: false,
  469. nameCache: null, // or specify a name cache object
  470. safari10: false,
  471. toplevel: false,
  472. warnings: false,
  473. }
  474. ```
  475. ### Source map options
  476. To generate a source map:
  477. ```javascript
  478. var result = UglifyJS.minify({"file1.js": "var a = function() {};"}, {
  479. sourceMap: {
  480. filename: "out.js",
  481. url: "out.js.map"
  482. }
  483. });
  484. console.log(result.code); // minified output
  485. console.log(result.map); // source map
  486. ```
  487. Note that the source map is not saved in a file, it's just returned in
  488. `result.map`. The value passed for `sourceMap.url` is only used to set
  489. `//# sourceMappingURL=out.js.map` in `result.code`. The value of
  490. `filename` is only used to set `file` attribute (see [the spec][sm-spec])
  491. in source map file.
  492. You can set option `sourceMap.url` to be `"inline"` and source map will
  493. be appended to code.
  494. You can also specify sourceRoot property to be included in source map:
  495. ```javascript
  496. var result = UglifyJS.minify({"file1.js": "var a = function() {};"}, {
  497. sourceMap: {
  498. root: "http://example.com/src",
  499. url: "out.js.map"
  500. }
  501. });
  502. ```
  503. If you're compressing compiled JavaScript and have a source map for it, you
  504. can use `sourceMap.content`:
  505. ```javascript
  506. var result = UglifyJS.minify({"compiled.js": "compiled code"}, {
  507. sourceMap: {
  508. content: "content from compiled.js.map",
  509. url: "minified.js.map"
  510. }
  511. });
  512. // same as before, it returns `code` and `map`
  513. ```
  514. If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.url`.
  515. ## Parse options
  516. - `bare_returns` (default `false`) -- support top level `return` statements
  517. - `ecma` (default: `8`) -- specify one of `5`, `6`, `7` or `8`. Note: this setting
  518. is not presently enforced except for ES8 optional trailing commas in function
  519. parameter lists and calls with `ecma` `8`.
  520. - `html5_comments` (default `true`)
  521. - `shebang` (default `true`) -- support `#!command` as the first line
  522. ## Compress options
  523. - `arrows` (default: `true`) -- Converts `()=>{return x}` to `()=>x`. Class
  524. and object literal methods will also be converted to arrow expressions if
  525. the resultant code is shorter: `m(){return x}` becomes `m:()=>x`.
  526. This transform requires that the `ecma` compress option is set to `6` or greater.
  527. - `booleans` (default: `true`) -- various optimizations for boolean context,
  528. for example `!!a ? b : c → a ? b : c`
  529. - `collapse_vars` (default: `true`) -- Collapse single-use non-constant variables,
  530. side effects permitting.
  531. - `comparisons` (default: `true`) -- apply certain optimizations to binary nodes,
  532. e.g. `!(a <= b) → a > b` (only when `unsafe_comps`), attempts to negate binary
  533. nodes, e.g. `a = !b && !c && !d && !e → a=!(b||c||d||e)` etc.
  534. - `computed_props` (default: `true`) -- Transforms constant computed properties
  535. into regular ones: `{["computed"]: 1}` is converted to `{computed: 1}`.
  536. - `conditionals` (default: `true`) -- apply optimizations for `if`-s and conditional
  537. expressions
  538. - `dead_code` (default: `true`) -- remove unreachable code
  539. - `drop_console` (default: `false`) -- Pass `true` to discard calls to
  540. `console.*` functions. If you wish to drop a specific function call
  541. such as `console.info` and/or retain side effects from function arguments
  542. after dropping the function call then use `pure_funcs` instead.
  543. - `drop_debugger` (default: `true`) -- remove `debugger;` statements
  544. - `ecma` (default: `5`) -- Pass `6` or greater to enable `compress` options that
  545. will transform ES5 code into smaller ES6+ equivalent forms.
  546. - `evaluate` (default: `true`) -- attempt to evaluate constant expressions
  547. - `expression` (default: `false`) -- Pass `true` to preserve completion values
  548. from terminal statements without `return`, e.g. in bookmarklets.
  549. - `global_defs` (default: `{}`) -- see [conditional compilation](#conditional-compilation)
  550. - `hoist_funs` (default: `false`) -- hoist function declarations
  551. - `hoist_props` (default: `true`) -- hoist properties from constant object and
  552. array literals into regular variables subject to a set of constraints. For example:
  553. `var o={p:1, q:2}; f(o.p, o.q);` is converted to `f(1, 2);`. Note: `hoist_props`
  554. works best with `mangle` enabled, the `compress` option `passes` set to `2` or higher,
  555. and the `compress` option `toplevel` enabled.
  556. - `hoist_vars` (default: `false`) -- hoist `var` declarations (this is `false`
  557. by default because it seems to increase the size of the output in general)
  558. - `if_return` (default: `true`) -- optimizations for if/return and if/continue
  559. - `inline` (default: `true`) -- inline calls to function with simple/`return` statement:
  560. - `false` -- same as `0`
  561. - `0` -- disabled inlining
  562. - `1` -- inline simple functions
  563. - `2` -- inline functions with arguments
  564. - `3` -- inline functions with arguments and variables
  565. - `true` -- same as `3`
  566. - `join_vars` (default: `true`) -- join consecutive `var` statements
  567. - `keep_classnames` (default: `false`) -- Pass `true` to prevent the
  568. compressor from discarding class names. See also: the `keep_classnames`
  569. [mangle option](#mangle).
  570. - `keep_fargs` (default: `true`) -- Prevents the compressor from discarding unused
  571. function arguments. You need this for code which relies on `Function.length`.
  572. - `keep_fnames` (default: `false`) -- Pass `true` to prevent the
  573. compressor from discarding function names. Useful for code relying on
  574. `Function.prototype.name`. See also: the `keep_fnames` [mangle option](#mangle).
  575. - `keep_infinity` (default: `false`) -- Pass `true` to prevent `Infinity` from
  576. being compressed into `1/0`, which may cause performance issues on Chrome.
  577. - `loops` (default: `true`) -- optimizations for `do`, `while` and `for` loops
  578. when we can statically determine the condition.
  579. - `negate_iife` (default: `true`) -- negate "Immediately-Called Function Expressions"
  580. where the return value is discarded, to avoid the parens that the
  581. code generator would insert.
  582. - `passes` (default: `1`) -- The maximum number of times to run compress.
  583. In some cases more than one pass leads to further compressed code. Keep in
  584. mind more passes will take more time.
  585. - `properties` (default: `true`) -- rewrite property access using the dot notation, for
  586. example `foo["bar"] → foo.bar`
  587. - `pure_funcs` (default: `null`) -- You can pass an array of names and
  588. UglifyJS will assume that those functions do not produce side
  589. effects. DANGER: will not check if the name is redefined in scope.
  590. An example case here, for instance `var q = Math.floor(a/b)`. If
  591. variable `q` is not used elsewhere, UglifyJS will drop it, but will
  592. still keep the `Math.floor(a/b)`, not knowing what it does. You can
  593. pass `pure_funcs: [ 'Math.floor' ]` to let it know that this
  594. function won't produce any side effect, in which case the whole
  595. statement would get discarded. The current implementation adds some
  596. overhead (compression will be slower).
  597. - `pure_getters` (default: `"strict"`) -- If you pass `true` for
  598. this, UglifyJS will assume that object property access
  599. (e.g. `foo.bar` or `foo["bar"]`) doesn't have any side effects.
  600. Specify `"strict"` to treat `foo.bar` as side-effect-free only when
  601. `foo` is certain to not throw, i.e. not `null` or `undefined`.
  602. - `reduce_funcs` (default: `true`) -- Allows single-use functions to be
  603. inlined as function expressions when permissible allowing further
  604. optimization. Enabled by default. Option depends on `reduce_vars`
  605. being enabled. Some code runs faster in the Chrome V8 engine if this
  606. option is disabled. Does not negatively impact other major browsers.
  607. - `reduce_vars` (default: `true`) -- Improve optimization on variables assigned with and
  608. used as constant values.
  609. - `sequences` (default: `true`) -- join consecutive simple statements using the
  610. comma operator. May be set to a positive integer to specify the maximum number
  611. of consecutive comma sequences that will be generated. If this option is set to
  612. `true` then the default `sequences` limit is `200`. Set option to `false` or `0`
  613. to disable. The smallest `sequences` length is `2`. A `sequences` value of `1`
  614. is grandfathered to be equivalent to `true` and as such means `200`. On rare
  615. occasions the default sequences limit leads to very slow compress times in which
  616. case a value of `20` or less is recommended.
  617. - `side_effects` (default: `true`) -- Pass `false` to disable potentially dropping
  618. functions marked as "pure". A function call is marked as "pure" if a comment
  619. annotation `/*@__PURE__*/` or `/*#__PURE__*/` immediately precedes the call. For
  620. example: `/*@__PURE__*/foo();`
  621. - `switches` (default: `true`) -- de-duplicate and remove unreachable `switch` branches
  622. - `toplevel` (default: `false`) -- drop unreferenced functions (`"funcs"`) and/or
  623. variables (`"vars"`) in the top level scope (`false` by default, `true` to drop
  624. both unreferenced functions and variables)
  625. - `top_retain` (default: `null`) -- prevent specific toplevel functions and
  626. variables from `unused` removal (can be array, comma-separated, RegExp or
  627. function. Implies `toplevel`)
  628. - `typeofs` (default: `true`) -- Transforms `typeof foo == "undefined"` into
  629. `foo === void 0`. Note: recommend to set this value to `false` for IE10 and
  630. earlier versions due to known issues.
  631. - `unsafe` (default: `false`) -- apply "unsafe" transformations (discussion below)
  632. - `unsafe_arrows` (default: `false`) -- Convert ES5 style anonymous function
  633. expressions to arrow functions if the function body does not reference `this`.
  634. Note: it is not always safe to perform this conversion if code relies on the
  635. the function having a `prototype`, which arrow functions lack.
  636. This transform requires that the `ecma` compress option is set to `6` or greater.
  637. - `unsafe_comps` (default: `false`) -- Reverse `<` and `<=` to `>` and `>=` to
  638. allow improved compression. This might be unsafe when an at least one of two
  639. operands is an object with computed values due the use of methods like `get`,
  640. or `valueOf`. This could cause change in execution order after operands in the
  641. comparison are switching. Compression only works if both `comparisons` and
  642. `unsafe_comps` are both set to true.
  643. - `unsafe_Function` (default: `false`) -- compress and mangle `Function(args, code)`
  644. when both `args` and `code` are string literals.
  645. - `unsafe_math` (default: `false`) -- optimize numerical expressions like
  646. `2 * x * 3` into `6 * x`, which may give imprecise floating point results.
  647. - `unsafe_methods` (default: false) -- Converts `{ m: function(){} }` to
  648. `{ m(){} }`. `ecma` must be set to `6` or greater to enable this transform.
  649. If `unsafe_methods` is a RegExp then key/value pairs with keys matching the
  650. RegExp will be converted to concise methods.
  651. Note: if enabled there is a risk of getting a "`<method name>` is not a
  652. constructor" TypeError should any code try to `new` the former function.
  653. - `unsafe_proto` (default: `false`) -- optimize expressions like
  654. `Array.prototype.slice.call(a)` into `[].slice.call(a)`
  655. - `unsafe_regexp` (default: `false`) -- enable substitutions of variables with
  656. `RegExp` values the same way as if they are constants.
  657. - `unsafe_undefined` (default: `false`) -- substitute `void 0` if there is a
  658. variable named `undefined` in scope (variable name will be mangled, typically
  659. reduced to a single character)
  660. - `unused` (default: `true`) -- drop unreferenced functions and variables (simple
  661. direct variable assignments do not count as references unless set to `"keep_assign"`)
  662. - `warnings` (default: `false`) -- display warnings when dropping unreachable
  663. code or unused declarations etc.
  664. ## Mangle options
  665. - `eval` (default `false`) -- Pass `true` to mangle names visible in scopes
  666. where `eval` or `with` are used.
  667. - `keep_classnames` (default `false`) -- Pass `true` to not mangle class names.
  668. See also: the `keep_classnames` [compress option](#compress-options).
  669. - `keep_fnames` (default `false`) -- Pass `true` to not mangle function names.
  670. Useful for code relying on `Function.prototype.name`. See also: the `keep_fnames`
  671. [compress option](#compress-options).
  672. - `reserved` (default `[]`) -- Pass an array of identifiers that should be
  673. excluded from mangling. Example: `["foo", "bar"]`.
  674. - `toplevel` (default `false`) -- Pass `true` to mangle names declared in the
  675. top level scope.
  676. - `safari10` (default `false`) -- Pass `true` to work around the Safari 10 loop
  677. iterator [bug](https://bugs.webkit.org/show_bug.cgi?id=171041)
  678. "Cannot declare a let variable twice".
  679. See also: the `safari10` [output option](#output-options).
  680. Examples:
  681. ```javascript
  682. // test.js
  683. var globalVar;
  684. function funcName(firstLongName, anotherLongName) {
  685. var myVariable = firstLongName + anotherLongName;
  686. }
  687. ```
  688. ```javascript
  689. var code = fs.readFileSync("test.js", "utf8");
  690. UglifyJS.minify(code).code;
  691. // 'function funcName(a,n){}var globalVar;'
  692. UglifyJS.minify(code, { mangle: { reserved: ['firstLongName'] } }).code;
  693. // 'function funcName(firstLongName,a){}var globalVar;'
  694. UglifyJS.minify(code, { mangle: { toplevel: true } }).code;
  695. // 'function n(n,a){}var a;'
  696. ```
  697. ### Mangle properties options
  698. - `builtins` (default: `false`) -- Use `true` to allow the mangling of builtin
  699. DOM properties. Not recommended to override this setting.
  700. - `debug` (default: `false`) -— Mangle names with the original name still present.
  701. Pass an empty string `""` to enable, or a non-empty string to set the debug suffix.
  702. - `keep_quoted` (default: `false`) -— Only mangle unquoted property names.
  703. - `regex` (default: `null`) -— Pass a RegExp literal to only mangle property
  704. names matching the regular expression.
  705. - `reserved` (default: `[]`) -- Do not mangle property names listed in the
  706. `reserved` array.
  707. ## Output options
  708. The code generator tries to output shortest code possible by default. In
  709. case you want beautified output, pass `--beautify` (`-b`). Optionally you
  710. can pass additional arguments that control the code output:
  711. - `ascii_only` (default `false`) -- escape Unicode characters in strings and
  712. regexps (affects directives with non-ascii characters becoming invalid)
  713. - `beautify` (default `true`) -- whether to actually beautify the output.
  714. Passing `-b` will set this to true, but you might need to pass `-b` even
  715. when you want to generate minified code, in order to specify additional
  716. arguments, so you can use `-b beautify=false` to override it.
  717. - `bracketize` (default `false`) -- always insert brackets in `if`, `for`,
  718. `do`, `while` or `with` statements, even if their body is a single
  719. statement.
  720. - `comments` (default `false`) -- pass `true` or `"all"` to preserve all
  721. comments, `"some"` to preserve some comments, a regular expression string
  722. (e.g. `/^!/`) or a function.
  723. - `ecma` (default `5`) -- set output printing mode. Set `ecma` to `6` or
  724. greater to emit shorthand object properties - i.e.: `{a}` instead of `{a: a}`.
  725. The `ecma` option will only change the output in direct control of the
  726. beautifier. Non-compatible features in the abstract syntax tree will still
  727. be output as is. For example: an `ecma` setting of `5` will **not** convert
  728. ES6+ code to ES5.
  729. - `indent_level` (default `4`)
  730. - `indent_start` (default `0`) -- prefix all lines by that many spaces
  731. - `inline_script` (default `false`) -- escape the slash in occurrences of
  732. `</script` in strings
  733. - `keep_quoted_props` (default `false`) -- when turned on, prevents stripping
  734. quotes from property names in object literals.
  735. - `max_line_len` (default `false`) -- maximum line length (for uglified code)
  736. - `preamble` (default `null`) -- when passed it must be a string and
  737. it will be prepended to the output literally. The source map will
  738. adjust for this text. Can be used to insert a comment containing
  739. licensing information, for example.
  740. - `preserve_line` (default `false`) -- pass `true` to preserve lines, but it
  741. only works if `beautify` is set to `false`.
  742. - `quote_keys` (default `false`) -- pass `true` to quote all keys in literal
  743. objects
  744. - `quote_style` (default `0`) -- preferred quote style for strings (affects
  745. quoted property names and directives as well):
  746. - `0` -- prefers double quotes, switches to single quotes when there are
  747. more double quotes in the string itself. `0` is best for gzip size.
  748. - `1` -- always use single quotes
  749. - `2` -- always use double quotes
  750. - `3` -- always use the original quotes
  751. - `safari10` (default `false`) -- set this option to `true` to work around
  752. the [Safari 10/11 await bug](https://bugs.webkit.org/show_bug.cgi?id=176685).
  753. See also: the `safari10` [mangle option](#mangle-options).
  754. - `semicolons` (default `true`) -- separate statements with semicolons. If
  755. you pass `false` then whenever possible we will use a newline instead of a
  756. semicolon, leading to more readable output of uglified code (size before
  757. gzip could be smaller; size after gzip insignificantly larger).
  758. - `shebang` (default `true`) -- preserve shebang `#!` in preamble (bash scripts)
  759. - `webkit` (default `false`) -- enable workarounds for WebKit bugs.
  760. PhantomJS users should set this option to `true`.
  761. - `width` (default `80`) -- only takes effect when beautification is on, this
  762. specifies an (orientative) line width that the beautifier will try to
  763. obey. It refers to the width of the line text (excluding indentation).
  764. It doesn't work very well currently, but it does make the code generated
  765. by UglifyJS more readable.
  766. - `wrap_iife` (default `false`) -- pass `true` to wrap immediately invoked
  767. function expressions. See
  768. [#640](https://github.com/mishoo/UglifyJS2/issues/640) for more details.
  769. # Miscellaneous
  770. ### Keeping copyright notices or other comments
  771. You can pass `--comments` to retain certain comments in the output. By
  772. default it will keep JSDoc-style comments that contain "@preserve",
  773. "@license" or "@cc_on" (conditional compilation for IE). You can pass
  774. `--comments all` to keep all the comments, or a valid JavaScript regexp to
  775. keep only comments that match this regexp. For example `--comments /^!/`
  776. will keep comments like `/*! Copyright Notice */`.
  777. Note, however, that there might be situations where comments are lost. For
  778. example:
  779. ```javascript
  780. function f() {
  781. /** @preserve Foo Bar */
  782. function g() {
  783. // this function is never called
  784. }
  785. return something();
  786. }
  787. ```
  788. Even though it has "@preserve", the comment will be lost because the inner
  789. function `g` (which is the AST node to which the comment is attached to) is
  790. discarded by the compressor as not referenced.
  791. The safest comments where to place copyright information (or other info that
  792. needs to be kept in the output) are comments attached to toplevel nodes.
  793. ### The `unsafe` `compress` option
  794. It enables some transformations that *might* break code logic in certain
  795. contrived cases, but should be fine for most code. You might want to try it
  796. on your own code, it should reduce the minified size. Here's what happens
  797. when this flag is on:
  798. - `new Array(1, 2, 3)` or `Array(1, 2, 3)` → `[ 1, 2, 3 ]`
  799. - `new Object()` → `{}`
  800. - `String(exp)` or `exp.toString()` → `"" + exp`
  801. - `new Object/RegExp/Function/Error/Array (...)` → we discard the `new`
  802. ### Conditional compilation
  803. You can use the `--define` (`-d`) switch in order to declare global
  804. variables that UglifyJS will assume to be constants (unless defined in
  805. scope). For example if you pass `--define DEBUG=false` then, coupled with
  806. dead code removal UglifyJS will discard the following from the output:
  807. ```javascript
  808. if (DEBUG) {
  809. console.log("debug stuff");
  810. }
  811. ```
  812. You can specify nested constants in the form of `--define env.DEBUG=false`.
  813. UglifyJS will warn about the condition being always false and about dropping
  814. unreachable code; for now there is no option to turn off only this specific
  815. warning, you can pass `warnings=false` to turn off *all* warnings.
  816. Another way of doing that is to declare your globals as constants in a
  817. separate file and include it into the build. For example you can have a
  818. `build/defines.js` file with the following:
  819. ```javascript
  820. var DEBUG = false;
  821. var PRODUCTION = true;
  822. // etc.
  823. ```
  824. and build your code like this:
  825. uglifyjs build/defines.js js/foo.js js/bar.js... -c
  826. UglifyJS will notice the constants and, since they cannot be altered, it
  827. will evaluate references to them to the value itself and drop unreachable
  828. code as usual. The build will contain the `const` declarations if you use
  829. them. If you are targeting < ES6 environments which does not support `const`,
  830. using `var` with `reduce_vars` (enabled by default) should suffice.
  831. ### Conditional compilation API
  832. You can also use conditional compilation via the programmatic API. With the difference that the
  833. property name is `global_defs` and is a compressor property:
  834. ```javascript
  835. var result = UglifyJS.minify(fs.readFileSync("input.js", "utf8"), {
  836. compress: {
  837. dead_code: true,
  838. global_defs: {
  839. DEBUG: false
  840. }
  841. }
  842. });
  843. ```
  844. To replace an identifier with an arbitrary non-constant expression it is
  845. necessary to prefix the `global_defs` key with `"@"` to instruct UglifyJS
  846. to parse the value as an expression:
  847. ```javascript
  848. UglifyJS.minify("alert('hello');", {
  849. compress: {
  850. global_defs: {
  851. "@alert": "console.log"
  852. }
  853. }
  854. }).code;
  855. // returns: 'console.log("hello");'
  856. ```
  857. Otherwise it would be replaced as string literal:
  858. ```javascript
  859. UglifyJS.minify("alert('hello');", {
  860. compress: {
  861. global_defs: {
  862. "alert": "console.log"
  863. }
  864. }
  865. }).code;
  866. // returns: '"console.log"("hello");'
  867. ```
  868. ### Using native Uglify AST with `minify()`
  869. ```javascript
  870. // example: parse only, produce native Uglify AST
  871. var result = UglifyJS.minify(code, {
  872. parse: {},
  873. compress: false,
  874. mangle: false,
  875. output: {
  876. ast: true,
  877. code: false // optional - faster if false
  878. }
  879. });
  880. // result.ast contains native Uglify AST
  881. ```
  882. ```javascript
  883. // example: accept native Uglify AST input and then compress and mangle
  884. // to produce both code and native AST.
  885. var result = UglifyJS.minify(ast, {
  886. compress: {},
  887. mangle: {},
  888. output: {
  889. ast: true,
  890. code: true // optional - faster if false
  891. }
  892. });
  893. // result.ast contains native Uglify AST
  894. // result.code contains the minified code in string form.
  895. ```
  896. ### Working with Uglify AST
  897. Transversal and transformation of the native AST can be performed through
  898. [`TreeWalker`](http://lisperator.net/uglifyjs/walk) and
  899. [`TreeTransformer`](http://lisperator.net/uglifyjs/transform) respectively.
  900. ### ESTree / SpiderMonkey AST
  901. UglifyJS has its own abstract syntax tree format; for
  902. [practical reasons](http://lisperator.net/blog/uglifyjs-why-not-switching-to-spidermonkey-ast/)
  903. we can't easily change to using the SpiderMonkey AST internally. However,
  904. UglifyJS now has a converter which can import a SpiderMonkey AST.
  905. For example [Acorn][acorn] is a super-fast parser that produces a
  906. SpiderMonkey AST. It has a small CLI utility that parses one file and dumps
  907. the AST in JSON on the standard output. To use UglifyJS to mangle and
  908. compress that:
  909. acorn file.js | uglifyjs -p spidermonkey -m -c
  910. The `-p spidermonkey` option tells UglifyJS that all input files are not
  911. JavaScript, but JS code described in SpiderMonkey AST in JSON. Therefore we
  912. don't use our own parser in this case, but just transform that AST into our
  913. internal AST.
  914. ### Use Acorn for parsing
  915. More for fun, I added the `-p acorn` option which will use Acorn to do all
  916. the parsing. If you pass this option, UglifyJS will `require("acorn")`.
  917. Acorn is really fast (e.g. 250ms instead of 380ms on some 650K code), but
  918. converting the SpiderMonkey tree that Acorn produces takes another 150ms so
  919. in total it's a bit more than just using UglifyJS's own parser.
  920. [acorn]: https://github.com/ternjs/acorn
  921. [sm-spec]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k
  922. ### Uglify Fast Minify Mode
  923. It's not well known, but whitespace removal and symbol mangling accounts
  924. for 95% of the size reduction in minified code for most JavaScript - not
  925. elaborate code transforms. One can simply disable `compress` to speed up
  926. Uglify builds by 3 to 4 times. In this fast `mangle`-only mode Uglify has
  927. comparable minify speeds and gzip sizes to
  928. [`butternut`](https://www.npmjs.com/package/butternut):
  929. | d3.js | minify size | gzip size | minify time (seconds) |
  930. | --- | ---: | ---: | ---: |
  931. | original | 451,131 | 108,733 | - |
  932. | uglify-js@3.0.24 mangle=false, compress=false | 316,600 | 85,245 | 0.70 |
  933. | uglify-js@3.0.24 mangle=true, compress=false | 220,216 | 72,730 | 1.13 |
  934. | butternut@0.4.6 | 217,568 | 72,738 | 1.41 |
  935. | uglify-js@3.0.24 mangle=true, compress=true | 212,511 | 71,560 | 3.36 |
  936. | babili@0.1.4 | 210,713 | 72,140 | 12.64 |
  937. To enable fast minify mode from the CLI use:
  938. ```
  939. uglifyjs file.js -m
  940. ```
  941. To enable fast minify mode with the API use:
  942. ```js
  943. UglifyJS.minify(code, { compress: false, mangle: true });
  944. ```