Update README
This commit is contained in:
208
README.md
208
README.md
@@ -52,70 +52,87 @@ a double dash to prevent input files being used as option arguments:
|
|||||||
The available options are:
|
The available options are:
|
||||||
|
|
||||||
```
|
```
|
||||||
--source-map Specify an output file where to generate source map.
|
--source-map Specify an output file where to generate source
|
||||||
[string]
|
map.
|
||||||
--source-map-root The path to the original source to be included in the
|
--source-map-root The path to the original source to be included
|
||||||
source map. [string]
|
in the source map.
|
||||||
--source-map-url The path to the source map to be added in //#
|
--source-map-url The path to the source map to be added in //#
|
||||||
sourceMappingURL. Defaults to the value passed with
|
sourceMappingURL. Defaults to the value passed
|
||||||
--source-map. [string]
|
with --source-map.
|
||||||
--source-map-include-sources
|
--source-map-include-sources Pass this flag if you want to include the
|
||||||
Pass this flag if you want to include the content of
|
content of source files in the source map as
|
||||||
source files in the source map as sourcesContent
|
sourcesContent property.
|
||||||
property. [boolean]
|
--in-source-map Input source map, useful if you're compressing
|
||||||
--in-source-map Input source map, useful if you're compressing JS that was
|
JS that was generated from some other original
|
||||||
generated from some other original code.
|
code.
|
||||||
--screw-ie8 Pass this flag if you don't care about full compliance
|
--screw-ie8 Pass this flag if you don't care about full
|
||||||
with Internet Explorer 6-8 quirks (by default UglifyJS
|
compliance with Internet Explorer 6-8 quirks
|
||||||
will try to be IE-proof). [boolean]
|
(by default UglifyJS will try to be IE-proof).
|
||||||
--expr Parse a single expression, rather than a program (for
|
--expr Parse a single expression, rather than a
|
||||||
parsing JSON) [boolean]
|
program (for parsing JSON)
|
||||||
-p, --prefix Skip prefix for original filenames that appear in source
|
-p, --prefix Skip prefix for original filenames that appear
|
||||||
maps. For example -p 3 will drop 3 directories from file
|
in source maps. For example -p 3 will drop 3
|
||||||
names and ensure they are relative paths. You can also
|
directories from file names and ensure they are
|
||||||
specify -p relative, which will make UglifyJS figure out
|
relative paths. You can also specify -p
|
||||||
itself the relative paths between original sources, the
|
relative, which will make UglifyJS figure out
|
||||||
source map and the output file. [string]
|
itself the relative paths between original
|
||||||
-o, --output Output file (default STDOUT).
|
sources, the source map and the output file.
|
||||||
-b, --beautify Beautify output/specify output options. [string]
|
-o, --output Output file (default STDOUT).
|
||||||
-m, --mangle Mangle names/pass mangler options. [string]
|
-b, --beautify Beautify output/specify output options.
|
||||||
-r, --reserved Reserved names to exclude from mangling.
|
-m, --mangle Mangle names/pass mangler options.
|
||||||
-c, --compress Enable compressor/pass compressor options. Pass options
|
-r, --reserved Reserved names to exclude from mangling.
|
||||||
like -c hoist_vars=false,if_return=false. Use -c with no
|
-c, --compress Enable compressor/pass compressor options. Pass
|
||||||
argument to use the default compression options. [string]
|
options like -c
|
||||||
-d, --define Global definitions [string]
|
hoist_vars=false,if_return=false. Use -c with
|
||||||
-e, --enclose Embed everything in a big function, with a configurable
|
no argument to use the default compression
|
||||||
parameter/argument list. [string]
|
options.
|
||||||
--comments Preserve copyright comments in the output. By default this
|
-d, --define Global definitions
|
||||||
works like Google Closure, keeping JSDoc-style comments
|
-e, --enclose Embed everything in a big function, with a
|
||||||
that contain "@license" or "@preserve". You can optionally
|
configurable parameter/argument list.
|
||||||
pass one of the following arguments to this flag:
|
--comments Preserve copyright comments in the output. By
|
||||||
- "all" to keep all comments
|
default this works like Google Closure, keeping
|
||||||
- a valid JS regexp (needs to start with a slash) to keep
|
JSDoc-style comments that contain "@license" or
|
||||||
only comments that match.
|
"@preserve". You can optionally pass one of the
|
||||||
Note that currently not *all* comments can be kept when
|
following arguments to this flag:
|
||||||
compression is on, because of dead code removal or
|
- "all" to keep all comments
|
||||||
cascading statements into sequences. [string]
|
- a valid JS regexp (needs to start with a
|
||||||
--preamble Preamble to prepend to the output. You can use this to
|
slash) to keep only comments that match.
|
||||||
insert a comment, for example for licensing information.
|
Note that currently not *all* comments can be
|
||||||
This will not be parsed, but the source map will adjust
|
kept when compression is on, because of dead
|
||||||
for its presence.
|
code removal or cascading statements into
|
||||||
--stats Display operations run time on STDERR. [boolean]
|
sequences.
|
||||||
--acorn Use Acorn for parsing. [boolean]
|
--preamble Preamble to prepend to the output. You can use
|
||||||
--spidermonkey Assume input files are SpiderMonkey AST format (as JSON).
|
this to insert a comment, for example for
|
||||||
[boolean]
|
licensing information. This will not be
|
||||||
--self Build itself (UglifyJS2) as a library (implies
|
parsed, but the source map will adjust for its
|
||||||
--wrap=UglifyJS --export-all) [boolean]
|
presence.
|
||||||
--wrap Embed everything in a big function, making the “exports”
|
--stats Display operations run time on STDERR.
|
||||||
and “global” variables available. You need to pass an
|
--acorn Use Acorn for parsing.
|
||||||
argument to this option to specify the name that your
|
--spidermonkey Assume input files are SpiderMonkey AST format
|
||||||
module will take when included in, say, a browser.
|
(as JSON).
|
||||||
[string]
|
--self Build itself (UglifyJS2) as a library (implies
|
||||||
--export-all Only used when --wrap, this tells UglifyJS to add code to
|
--wrap=UglifyJS --export-all)
|
||||||
automatically export all globals. [boolean]
|
--wrap Embed everything in a big function, making the
|
||||||
--lint Display some scope warnings [boolean]
|
“exports” and “global” variables available. You
|
||||||
-v, --verbose Verbose [boolean]
|
need to pass an argument to this option to
|
||||||
-V, --version Print version number and exit. [boolean]
|
specify the name that your module will take
|
||||||
|
when included in, say, a browser.
|
||||||
|
--export-all Only used when --wrap, this tells UglifyJS to
|
||||||
|
add code to automatically export all globals.
|
||||||
|
--lint Display some scope warnings
|
||||||
|
-v, --verbose Verbose
|
||||||
|
-V, --version Print version number and exit.
|
||||||
|
--noerr Don't throw an error for unknown options in -c,
|
||||||
|
-b or -m.
|
||||||
|
--bare-returns Allow return outside of functions. Useful when
|
||||||
|
minifying CommonJS modules.
|
||||||
|
--keep-fnames Do not mangle/drop function names. Useful for
|
||||||
|
code relying on Function.prototype.name.
|
||||||
|
--reserved-file File containing reserved names
|
||||||
|
--reserve-domprops Make (most?) DOM properties reserved for
|
||||||
|
--mangle-props
|
||||||
|
--mangle-props Mangle property names
|
||||||
|
--name-cache File to hold mangled names mappings
|
||||||
```
|
```
|
||||||
|
|
||||||
Specify `--output` (`-o`) to declare the output file. Otherwise the output
|
Specify `--output` (`-o`) to declare the output file. Otherwise the output
|
||||||
@@ -189,6 +206,69 @@ comma-separated list of names. For example:
|
|||||||
|
|
||||||
to prevent the `require`, `exports` and `$` names from being changed.
|
to prevent the `require`, `exports` and `$` names from being changed.
|
||||||
|
|
||||||
|
### Mangling property names (`--mangle-props`)
|
||||||
|
|
||||||
|
**Note:** this will probably break your code. Mangling property names is a
|
||||||
|
separate step, different from variable name mangling. Pass
|
||||||
|
`--mangle-props`. It will mangle all properties that are seen in some
|
||||||
|
object literal, or that are assigned to. For example:
|
||||||
|
|
||||||
|
```js
|
||||||
|
var x = {
|
||||||
|
foo: 1
|
||||||
|
};
|
||||||
|
|
||||||
|
x.bar = 2;
|
||||||
|
x["baz"] = 3;
|
||||||
|
x[condition ? "moo" : "boo"] = 4;
|
||||||
|
console.log(x.something());
|
||||||
|
```
|
||||||
|
|
||||||
|
In the above code, `foo`, `bar`, `baz`, `moo` and `boo` will be replaced
|
||||||
|
with single characters, while `something()` will be left as is.
|
||||||
|
|
||||||
|
In order for this to be of any use, we should avoid mangling standard JS
|
||||||
|
names. For instance, if your code would contain `x.length = 10`, then
|
||||||
|
`length` becomes a candidate for mangling and it will be mangled throughout
|
||||||
|
the code, regardless if it's being used as part of your own objects or
|
||||||
|
accessing an array's length. To avoid that, you can use `--reserved-file`
|
||||||
|
to pass a filename that should contain the names to be excluded from
|
||||||
|
mangling. This file can be used both for excluding variable names and
|
||||||
|
property names. It could look like this, for example:
|
||||||
|
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
"vars": [ "define", "require", ... ],
|
||||||
|
"props": [ "length", "prototype", ... ]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`--reserved-file` can be an array of file names (either a single
|
||||||
|
comma-separated argument, or you can pass multiple `--reserved-file`
|
||||||
|
arguments) — in this case it will exclude names from all those files.
|
||||||
|
|
||||||
|
A default exclusion file is provided in `tools/domprops.json` which should
|
||||||
|
cover most standard JS and DOM properties defined in various browsers. Pass
|
||||||
|
`--reserve-domprops` to read that in.
|
||||||
|
|
||||||
|
When you compress multiple files using this option, in order for them to
|
||||||
|
work together in the end we need to ensure somehow that one property gets
|
||||||
|
mangled to the same name in all of them. For this, pass `--name-cache
|
||||||
|
filename.json` and UglifyJS will maintain these mappings in a file which can
|
||||||
|
then be reused. It should be initially empty. Example:
|
||||||
|
|
||||||
|
```
|
||||||
|
rm -f /tmp/cache.json # start fresh
|
||||||
|
uglifyjs file1.js file2.js --mangle-props --name-cache /tmp/cache.json -o part1.js
|
||||||
|
uglifyjs file3.js file4.js --mangle-props --name-cache /tmp/cache.json -o part2.js
|
||||||
|
```
|
||||||
|
|
||||||
|
Now, `part1.js` and `part2.js` will be consistent with each other in terms
|
||||||
|
of mangled property names.
|
||||||
|
|
||||||
|
Using the name cache is not necessary if you compress all your files in a
|
||||||
|
single call to UglifyJS.
|
||||||
|
|
||||||
## Compressor options
|
## Compressor options
|
||||||
|
|
||||||
You need to pass `--compress` (`-c`) to enable the compressor. Optionally
|
You need to pass `--compress` (`-c`) to enable the compressor. Optionally
|
||||||
|
|||||||
Reference in New Issue
Block a user