mirror of
https://github.com/S2-/minifyfromhtml.git
synced 2025-08-02 20:00:05 +02:00
update minify
This commit is contained in:
179
node_modules/terser/README.md
generated
vendored
179
node_modules/terser/README.md
generated
vendored
@@ -1,29 +1,37 @@
|
||||
terser
|
||||
======
|
||||
<h1><img src="https://terser.org/img/terser-banner-logo.png" alt="Terser" width="400"></h1>
|
||||
|
||||

|
||||
[![NPM Version][npm-image]][npm-url]
|
||||
[![NPM Downloads][downloads-image]][downloads-url]
|
||||
[![Travis Build][travis-image]][travis-url]
|
||||
[![Opencollective financial contributors][opencollective-contributors]][opencollective-url]
|
||||
|
||||
A JavaScript parser and mangler/compressor toolkit for ES6+.
|
||||
|
||||
*note*: You can support this project on patreon: <a target="_blank" rel="nofollow" href="https://www.patreon.com/fabiosantoscode"><img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" alt="patron" width="100px" height="auto"></a>. Check out PATRONS.md for our first-tier patrons.
|
||||
*note*: You can support this project on patreon: <a target="_blank" rel="nofollow" href="https://www.patreon.com/fabiosantoscode"><img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" alt="patron" width="100px" height="auto"></a>. Check out [PATRONS.md](https://github.com/terser/terser/blob/master/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](https://npmjs.com/package/prettier).
|
||||
|
||||
[](https://travis-ci.org/terser-js/terser)
|
||||
Find the changelog in [CHANGELOG.md](https://github.com/terser/terser/blob/master/CHANGELOG.md)
|
||||
|
||||
Find the changelog in [CHANGELOG.md](https://github.com/terser-js/terser/blob/master/CHANGELOG.md)
|
||||
|
||||
A JavaScript parser, mangler/compressor and beautifier toolkit for ES6+.
|
||||
|
||||
[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
|
||||
[travis-image]: https://img.shields.io/travis/terser/terser/master.svg
|
||||
[travis-url]: https://travis-ci.org/terser/terser
|
||||
[opencollective-contributors]: https://opencollective.com/terser/tiers/badge.svg
|
||||
[opencollective-url]: https://opencollective.com/terser
|
||||
|
||||
Why choose terser?
|
||||
------------------
|
||||
|
||||
`uglify-es` is [no longer maintained](https://github.com/mishoo/UglifyJS2/issues/3156#issuecomment-392943058) and `uglify-js` does not support ES6+.
|
||||
|
||||
**`terser`** is a fork of `uglify-es` that retains API and CLI compatibility
|
||||
**`terser`** is a fork of `uglify-es` that mostly retains API and CLI compatibility
|
||||
with `uglify-es` and `uglify-js@3`.
|
||||
|
||||
Install
|
||||
@@ -39,7 +47,7 @@ From NPM for use as a command line app:
|
||||
From NPM for programmatic use:
|
||||
|
||||
npm install terser
|
||||
|
||||
|
||||
# Command line usage
|
||||
|
||||
terser [input files] [options]
|
||||
@@ -86,7 +94,10 @@ a double dash to prevent input files being used as option arguments:
|
||||
`debug` Add debug prefix and suffix.
|
||||
`domprops` Mangle property names that overlaps
|
||||
with DOM properties.
|
||||
`keep_quoted` Only mangle unquoted properties.
|
||||
`keep_quoted` Only mangle unquoted properties, quoted
|
||||
properties are automatically reserved.
|
||||
`strict` disables quoted properties
|
||||
being automatically reserved.
|
||||
`regex` Only mangle matched property names.
|
||||
`reserved` List of names that should not be mangled.
|
||||
-b, --beautify [options] Specify output options:
|
||||
@@ -103,6 +114,7 @@ a double dash to prevent input files being used as option arguments:
|
||||
`wrap_iife` Wrap IIFEs in parenthesis. Note: you may
|
||||
want to disable `negate_iife` under
|
||||
compressor options.
|
||||
`wrap_func_args` Wrap function arguments in parenthesis.
|
||||
-o, --output <file> Output file path (default STDOUT). Specify `ast` or
|
||||
`spidermonkey` to write Terser or SpiderMonkey AST
|
||||
as JSON to STDOUT respectively.
|
||||
@@ -112,6 +124,7 @@ a double dash to prevent input files being used as option arguments:
|
||||
"@preserve". You can optionally pass one of the
|
||||
following arguments to this flag:
|
||||
- "all" to keep all comments
|
||||
- `false` to omit comments in the output
|
||||
- a valid JS RegExp like `/foo/` or `/^!/` to
|
||||
keep only matching comments.
|
||||
Note that currently not *all* comments can be
|
||||
@@ -252,7 +265,7 @@ way to use this is to use the `regex` option like so:
|
||||
terser example.js -c -m --mangle-props regex=/_$/
|
||||
```
|
||||
|
||||
This will mangle all properties that start with an
|
||||
This will mangle all properties that end with an
|
||||
underscore. So you can use it to mangle internal methods.
|
||||
|
||||
By default, it will mangle all properties in the
|
||||
@@ -280,38 +293,38 @@ console.log(x.calc());
|
||||
```
|
||||
Mangle all properties (except for JavaScript `builtins`) (**very** unsafe):
|
||||
```bash
|
||||
$ terser example.js -c -m --mangle-props
|
||||
$ terser example.js -c passes=2 -m --mangle-props
|
||||
```
|
||||
```javascript
|
||||
var x={o:0,_:1,l:function(){return this._+this.o}};x.t=2,x.o=3,console.log(x.l());
|
||||
var x={o:3,t:1,i:function(){return this.t+this.o},s:2};console.log(x.i());
|
||||
```
|
||||
Mangle all properties except for `reserved` properties (still very unsafe):
|
||||
```bash
|
||||
$ terser example.js -c -m --mangle-props reserved=[foo_,bar_]
|
||||
$ terser example.js -c passes=2 -m --mangle-props reserved=[foo_,bar_]
|
||||
```
|
||||
```javascript
|
||||
var x={o:0,foo_:1,_:function(){return this.foo_+this.o}};x.bar_=2,x.o=3,console.log(x._());
|
||||
var x={o:3,foo_:1,t:function(){return this.foo_+this.o},bar_:2};console.log(x.t());
|
||||
```
|
||||
Mangle all properties matching a `regex` (not as unsafe but still unsafe):
|
||||
```bash
|
||||
$ terser example.js -c -m --mangle-props regex=/_$/
|
||||
$ terser example.js -c passes=2 -m --mangle-props regex=/_$/
|
||||
```
|
||||
```javascript
|
||||
var x={o:0,_:1,calc:function(){return this._+this.o}};x.l=2,x.o=3,console.log(x.calc());
|
||||
var x={o:3,t:1,calc:function(){return this.t+this.o},i:2};console.log(x.calc());
|
||||
```
|
||||
|
||||
Combining mangle properties options:
|
||||
```bash
|
||||
$ terser example.js -c -m --mangle-props regex=/_$/,reserved=[bar_]
|
||||
$ terser example.js -c passes=2 -m --mangle-props regex=/_$/,reserved=[bar_]
|
||||
```
|
||||
```javascript
|
||||
var x={o:0,_:1,calc:function(){return this._+this.o}};x.bar_=2,x.o=3,console.log(x.calc());
|
||||
var x={o:3,t:1,calc:function(){return this.t+this.o},bar_:2};console.log(x.calc());
|
||||
```
|
||||
|
||||
In order for this to be of any use, we avoid mangling standard JS names by
|
||||
default (`--mangle-props builtins` to override).
|
||||
|
||||
A default exclusion file is provided in `tools/domprops.json` which should
|
||||
A default exclusion file is provided in `tools/domprops.js` which should
|
||||
cover most standard JS and DOM properties defined in various browsers. Pass
|
||||
`--mangle-props domprops` to disable this feature.
|
||||
|
||||
@@ -521,8 +534,8 @@ if (result.error) throw result.error;
|
||||
|
||||
## Minify options
|
||||
|
||||
- `ecma` (default `undefined`) - pass `5`, `6`, `7` or `8` to override `parse`,
|
||||
`compress` and `output` options.
|
||||
- `ecma` (default `undefined`) - pass `5`, `2015`, `2016` or `2017` to override `parse`,
|
||||
`compress` and `output`'s `ecma` options.
|
||||
|
||||
- `warnings` (default `false`) — pass `true` to return compressor warnings
|
||||
in `result.warnings`. Use the value `"verbose"` for more detailed warnings.
|
||||
@@ -598,7 +611,7 @@ if (result.error) throw result.error;
|
||||
sourceMap: {
|
||||
// source map options
|
||||
},
|
||||
ecma: 5, // specify one of: 5, 6, 7 or 8
|
||||
ecma: 5, // specify one of: 5, 2015, 2016, 2017 or 2018
|
||||
keep_classnames: false,
|
||||
keep_fnames: false,
|
||||
ie8: false,
|
||||
@@ -657,13 +670,15 @@ var result = Terser.minify({"compiled.js": "compiled code"}, {
|
||||
|
||||
If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.url`.
|
||||
|
||||
If you happen to need the source map as a raw object, set `sourceMap.asObject` to `true`.
|
||||
|
||||
## Parse options
|
||||
|
||||
- `bare_returns` (default `false`) -- support top level `return` statements
|
||||
|
||||
- `ecma` (default: `8`) -- specify one of `5`, `6`, `7` or `8`. Note: this setting
|
||||
- `ecma` (default: `2017`) -- specify one of `5`, `2015`, `2016` or `2017`. Note: this setting
|
||||
is not presently enforced except for ES8 optional trailing commas in function
|
||||
parameter lists and calls with `ecma` `8`.
|
||||
parameter lists and calls with `ecma` `2017`.
|
||||
|
||||
- `html5_comments` (default `true`)
|
||||
|
||||
@@ -671,9 +686,10 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
||||
|
||||
## Compress options
|
||||
|
||||
- `arrows` (default: `true`) -- Converts `()=>{return x}` to `()=>x`. Class
|
||||
and object literal methods will also be converted to arrow expressions if
|
||||
the resultant code is shorter: `m(){return x}` becomes `m:()=>x`.
|
||||
- `arrows` (default: `true`) -- Class and object literal methods are converted
|
||||
will also be converted to arrow expressions if the resultant code is shorter:
|
||||
`m(){return x}` becomes `m:()=>x`. To do this to regular ES5 functions which
|
||||
don't use `this` or `arguments`, see `unsafe_arrows`.
|
||||
|
||||
- `arguments` (default: `false`) -- replace `arguments[index]` with function
|
||||
parameter name whenever possible.
|
||||
@@ -712,7 +728,7 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
||||
|
||||
- `drop_debugger` (default: `true`) -- remove `debugger;` statements
|
||||
|
||||
- `ecma` (default: `5`) -- Pass `6` or greater to enable `compress` options that
|
||||
- `ecma` (default: `5`) -- Pass `2015` or greater to enable `compress` options that
|
||||
will transform ES5 code into smaller ES6+ equivalent forms.
|
||||
|
||||
- `evaluate` (default: `true`) -- attempt to evaluate constant expressions
|
||||
@@ -754,7 +770,7 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
||||
|
||||
- `keep_fnames` (default: `false`) -- Pass `true` to prevent the
|
||||
compressor from discarding function names. Pass a regular expression to only keep
|
||||
class names matching that regex. Useful for code relying on `Function.prototype.name`.
|
||||
function names matching that regex. Useful for code relying on `Function.prototype.name`.
|
||||
See also: the `keep_fnames` [mangle option](#mangle).
|
||||
|
||||
- `keep_infinity` (default: `false`) -- Pass `true` to prevent `Infinity` from
|
||||
@@ -794,11 +810,7 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
||||
Specify `"strict"` to treat `foo.bar` as side-effect-free only when
|
||||
`foo` is certain to not throw, i.e. not `null` or `undefined`.
|
||||
|
||||
- `reduce_funcs` (default: `true`) -- Allows single-use functions to be
|
||||
inlined as function expressions when permissible allowing further
|
||||
optimization. Enabled by default. Option depends on `reduce_vars`
|
||||
being enabled. Some code runs faster in the Chrome V8 engine if this
|
||||
option is disabled. Does not negatively impact other major browsers.
|
||||
- `reduce_funcs` (legacy option, safely ignored for backwards compatibility).
|
||||
|
||||
- `reduce_vars` (default: `true`) -- Improve optimization on variables assigned with and
|
||||
used as constant values.
|
||||
@@ -813,7 +825,7 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
||||
case a value of `20` or less is recommended.
|
||||
|
||||
- `side_effects` (default: `true`) -- Pass `false` to disable potentially dropping
|
||||
functions marked as "pure". A function call is marked as "pure" if a comment
|
||||
function calls marked as "pure". A function call is marked as "pure" if a comment
|
||||
annotation `/*@__PURE__*/` or `/*#__PURE__*/` immediately precedes the call. For
|
||||
example: `/*@__PURE__*/foo();`
|
||||
|
||||
@@ -838,7 +850,7 @@ If you're using the `X-SourceMap` header instead, you can just omit `sourceMap.u
|
||||
expressions to arrow functions if the function body does not reference `this`.
|
||||
Note: it is not always safe to perform this conversion if code relies on the
|
||||
the function having a `prototype`, which arrow functions lack.
|
||||
This transform requires that the `ecma` compress option is set to `6` or greater.
|
||||
This transform requires that the `ecma` compress option is set to `2015` or greater.
|
||||
|
||||
- `unsafe_comps` (default: `false`) -- Reverse `<` and `<=` to `>` and `>=` to
|
||||
allow improved compression. This might be unsafe when an at least one of two
|
||||
@@ -928,20 +940,28 @@ Terser.minify(code, { mangle: { toplevel: true } }).code;
|
||||
|
||||
### Mangle properties options
|
||||
|
||||
- `builtins` (default: `false`) -- Use `true` to allow the mangling of builtin
|
||||
- `builtins` (default: `false`) — Use `true` to allow the mangling of builtin
|
||||
DOM properties. Not recommended to override this setting.
|
||||
|
||||
- `debug` (default: `false`) -— Mangle names with the original name still present.
|
||||
- `debug` (default: `false`) — Mangle names with the original name still present.
|
||||
Pass an empty string `""` to enable, or a non-empty string to set the debug suffix.
|
||||
|
||||
- `keep_quoted` (default: `false`) -— Only mangle unquoted property names.
|
||||
- `keep_quoted` (default: `false`) — Only mangle unquoted property names.
|
||||
- `true` -- Quoted property names are automatically reserved and any unquoted
|
||||
property names will not be mangled.
|
||||
- `"strict"` -- Advanced, all unquoted property names are mangled unless
|
||||
explicitly reserved.
|
||||
|
||||
- `regex` (default: `null`) -— Pass a RegExp literal to only mangle property
|
||||
names matching the regular expression.
|
||||
- `regex` (default: `null`) — Pass a [RegExp literal or pattern string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) to only mangle property matching the regular expression.
|
||||
|
||||
- `reserved` (default: `[]`) -- Do not mangle property names listed in the
|
||||
- `reserved` (default: `[]`) — Do not mangle property names listed in the
|
||||
`reserved` array.
|
||||
|
||||
- `undeclared` (default: `false`) - Mangle those names when they are accessed
|
||||
as properties of known top level variables but their declarations are never
|
||||
found in input code. May be useful when only minifying parts of a project.
|
||||
See [#397](https://github.com/terser/terser/issues/397) for more details.
|
||||
|
||||
## Output options
|
||||
|
||||
The code generator tries to output shortest code possible by default. In
|
||||
@@ -960,11 +980,12 @@ can pass additional arguments that control the code output:
|
||||
`do`, `while` or `with` statements, even if their body is a single
|
||||
statement.
|
||||
|
||||
- `comments` (default `false`) -- pass `true` or `"all"` to preserve all
|
||||
comments, `"some"` to preserve some comments, a regular expression string
|
||||
- `comments` (default `"some"`) -- by default it keeps JSDoc-style comments
|
||||
that contain "@license" or "@preserve", pass `true` or `"all"` to preserve all
|
||||
comments, `false` to omit comments in the output, a regular expression string
|
||||
(e.g. `/^!/`) or a function.
|
||||
|
||||
- `ecma` (default `5`) -- set output printing mode. Set `ecma` to `6` or
|
||||
- `ecma` (default `5`) -- set output printing mode. Set `ecma` to `2015` or
|
||||
greater to emit shorthand object properties - i.e.: `{a}` instead of `{a: a}`.
|
||||
The `ecma` option will only change the output in direct control of the
|
||||
beautifier. Non-compatible features in the abstract syntax tree will still
|
||||
@@ -978,6 +999,9 @@ can pass additional arguments that control the code output:
|
||||
- `inline_script` (default `true`) -- escape HTML comments and the slash in
|
||||
occurrences of `</script>` in strings
|
||||
|
||||
- `keep_numbers` (default `false`) -- keep number literals as it was in original code
|
||||
(disables optimizations like converting `1000000` into `1e6`)
|
||||
|
||||
- `keep_quoted_props` (default `false`) -- when turned on, prevents stripping
|
||||
quotes from property names in object literals.
|
||||
|
||||
@@ -999,6 +1023,8 @@ can pass additional arguments that control the code output:
|
||||
- `2` -- always use double quotes
|
||||
- `3` -- always use the original quotes
|
||||
|
||||
- `preserve_annotations` -- (default `false`) -- Preserve [Terser annotations](#annotations) in the output.
|
||||
|
||||
- `safari10` (default `false`) -- set this option to `true` to work around
|
||||
the [Safari 10/11 await bug](https://bugs.webkit.org/show_bug.cgi?id=176685).
|
||||
See also: the `safari10` [mangle option](#mangle-options).
|
||||
@@ -1017,6 +1043,10 @@ can pass additional arguments that control the code output:
|
||||
function expressions. See
|
||||
[#640](https://github.com/mishoo/UglifyJS2/issues/640) for more details.
|
||||
|
||||
- `wrap_func_args` (default `true`) -- pass `false` if you do not want to wrap
|
||||
function expressions that are passed as arguments, in parenthesis. See
|
||||
[OptimizeJS](https://github.com/nolanlawson/optimize-js) for more details.
|
||||
|
||||
# Miscellaneous
|
||||
|
||||
### Keeping copyright notices or other comments
|
||||
@@ -1173,6 +1203,30 @@ var result = Terser.minify(ast, {
|
||||
// result.code contains the minified code in string form.
|
||||
```
|
||||
|
||||
|
||||
### Annotations
|
||||
|
||||
Annotations in Terser are a way to tell it to treat a certain function call differently. The following annotations are available:
|
||||
|
||||
* `/*@__INLINE__*/` - forces a function to be inlined somewhere.
|
||||
* `/*@__NOINLINE__*/` - Makes sure the called function is not inlined into the call site.
|
||||
* `/*@__PURE__*/` - Marks a function call as pure. That means, it can safely be dropped.
|
||||
|
||||
You can use either a `@` sign at the start, or a `#`.
|
||||
|
||||
Here are some examples on how to use them:
|
||||
|
||||
```javascript
|
||||
/*@__INLINE__*/
|
||||
function_always_inlined_here()
|
||||
|
||||
/*#__NOINLINE__*/
|
||||
function_cant_be_inlined_into_here()
|
||||
|
||||
const x = /*#__PURE__*/i_am_dropped_if_x_is_not_used()
|
||||
```
|
||||
|
||||
|
||||
### Working with Terser AST
|
||||
|
||||
Traversal and transformation of the native AST can be performed through
|
||||
@@ -1298,8 +1352,39 @@ In the terser CLI we use [source-map-support](https://npmjs.com/source-map-suppo
|
||||
|
||||
# README.md Patrons:
|
||||
|
||||
*note*: You can support this project on patreon: <a target="_blank" rel="nofollow" href="https://www.patreon.com/terser_ecmacomp_maintainer"><img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" alt="patron" width="100px" height="auto"></a>. Check out PATRONS.md for our first-tier patrons.
|
||||
*note*: You can support this project on patreon: <a target="_blank" rel="nofollow" href="https://www.patreon.com/fabiosantoscode"><img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" alt="patron" width="100px" height="auto"></a>. Check out [PATRONS.md](https://github.com/terser/terser/blob/master/PATRONS.md) for our first-tier patrons.
|
||||
|
||||
These are the second-tier patrons. Great thanks for your support!
|
||||
|
||||
* CKEditor 
|
||||
* 38elements 
|
||||
|
||||
## Contributors
|
||||
|
||||
### Code Contributors
|
||||
|
||||
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
|
||||
<a href="https://github.com/terser/terser/graphs/contributors"><img src="https://opencollective.com/terser/contributors.svg?width=890&button=false" /></a>
|
||||
|
||||
### Financial Contributors
|
||||
|
||||
Become a financial contributor and help us sustain our community. [[Contribute](https://opencollective.com/terser/contribute)]
|
||||
|
||||
#### Individuals
|
||||
|
||||
<a href="https://opencollective.com/terser"><img src="https://opencollective.com/terser/individuals.svg?width=890"></a>
|
||||
|
||||
#### Organizations
|
||||
|
||||
Support this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/terser/contribute)]
|
||||
|
||||
<a href="https://opencollective.com/terser/organization/0/website"><img src="https://opencollective.com/terser/organization/0/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/terser/organization/1/website"><img src="https://opencollective.com/terser/organization/1/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/terser/organization/2/website"><img src="https://opencollective.com/terser/organization/2/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/terser/organization/3/website"><img src="https://opencollective.com/terser/organization/3/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/terser/organization/4/website"><img src="https://opencollective.com/terser/organization/4/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/terser/organization/5/website"><img src="https://opencollective.com/terser/organization/5/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/terser/organization/6/website"><img src="https://opencollective.com/terser/organization/6/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/terser/organization/7/website"><img src="https://opencollective.com/terser/organization/7/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/terser/organization/8/website"><img src="https://opencollective.com/terser/organization/8/avatar.svg"></a>
|
||||
<a href="https://opencollective.com/terser/organization/9/website"><img src="https://opencollective.com/terser/organization/9/avatar.svg"></a>
|
||||
|
Reference in New Issue
Block a user