update documentation (#1909)
- clarify options on `--source-map` - fix `minify()` examples fixes #1905
This commit is contained in:
88
README.md
88
README.md
@@ -7,7 +7,7 @@ UglifyJS is a JavaScript parser, minifier, compressor and beautifier toolkit.
|
|||||||
#### Note:
|
#### Note:
|
||||||
- **`uglify-js@3.x` has a new API and CLI and is not backwards compatible with [`uglify-js@2.x`](https://github.com/mishoo/UglifyJS2/tree/v2.x)**.
|
- **`uglify-js@3.x` has a new API and CLI and is not backwards compatible with [`uglify-js@2.x`](https://github.com/mishoo/UglifyJS2/tree/v2.x)**.
|
||||||
- **Documentation for UglifyJS `2.x` releases can be found [here](https://github.com/mishoo/UglifyJS2/tree/v2.x)**.
|
- **Documentation for UglifyJS `2.x` releases can be found [here](https://github.com/mishoo/UglifyJS2/tree/v2.x)**.
|
||||||
- Release versions of `uglify-js` only support ECMAScript 5 (ES5).
|
- Release versions of `uglify-js` only support ECMAScript 5 (ES5).
|
||||||
- Those wishing to minify
|
- Those wishing to minify
|
||||||
ES2015+ (ES6+) should use the `npm` package [**uglify-es**](https://github.com/mishoo/UglifyJS2/tree/harmony).
|
ES2015+ (ES6+) should use the `npm` package [**uglify-es**](https://github.com/mishoo/UglifyJS2/tree/harmony).
|
||||||
|
|
||||||
@@ -149,16 +149,21 @@ debugging your compressed JavaScript. To get a source map, pass
|
|||||||
`--source-map --output output.js` (source map will be written out to
|
`--source-map --output output.js` (source map will be written out to
|
||||||
`output.js.map`).
|
`output.js.map`).
|
||||||
|
|
||||||
Additionally you might need `--source-map root=<URL>` to pass the URL where
|
Additional options:
|
||||||
the original files can be found. Use `--source-map url=<URL>` to specify
|
|
||||||
the URL where the source map can be found.
|
- `--source-map filename=<NAME>` to specify the name of the source map.
|
||||||
|
|
||||||
|
- `--source-map root=<URL>` to pass the URL where the original files can be found.
|
||||||
|
Otherwise UglifyJS assumes HTTP `X-SourceMap` is being used and will omit the
|
||||||
|
`//# sourceMappingURL=` directive.
|
||||||
|
|
||||||
|
- `--source-map url=<URL>` to specify the URL where the source map can be found.
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
uglifyjs /home/doe/work/foo/src/js/file1.js \
|
uglifyjs js/file1.js js/file2.js \
|
||||||
/home/doe/work/foo/src/js/file2.js \
|
|
||||||
-o foo.min.js -c -m \
|
-o foo.min.js -c -m \
|
||||||
--source-map base="/home/doe/work/foo/src",root="http://foo.com/src"
|
--source-map root="http://foo.com/src",url=foo.min.js.map
|
||||||
|
|
||||||
The above will compress and mangle `file1.js` and `file2.js`, will drop the
|
The above will compress and mangle `file1.js` and `file2.js`, will drop the
|
||||||
output in `foo.min.js` and the source map in `foo.min.js.map`. The source
|
output in `foo.min.js` and the source map in `foo.min.js.map`. The source
|
||||||
@@ -177,11 +182,9 @@ CoffeeScript → compiled JS, UglifyJS can generate a map from CoffeeScript →
|
|||||||
compressed JS by mapping every token in the compiled JS to its original
|
compressed JS by mapping every token in the compiled JS to its original
|
||||||
location.
|
location.
|
||||||
|
|
||||||
To use this feature you need to pass `--in-source-map
|
To use this feature pass `--source-map conetent="/path/to/input/source.map"`
|
||||||
/path/to/input/source.map` or `--in-source-map inline` if the source map is
|
or `--source-map content=inline` if the source map is included inline with
|
||||||
included inline with the sources. Normally the input source map should also
|
the sources.
|
||||||
point to the file containing the generated JS, so if that's correct you can
|
|
||||||
omit input files from the command line.
|
|
||||||
|
|
||||||
## Mangler options
|
## Mangler options
|
||||||
|
|
||||||
@@ -464,7 +467,7 @@ You can also use conditional compilation via the programmatic API. With the diff
|
|||||||
property name is `global_defs` and is a compressor property:
|
property name is `global_defs` and is a compressor property:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
uglifyJS.minify([ "input.js"], {
|
uglifyJS.minify(fs.readFileSync("input.js", "utf8"), {
|
||||||
compress: {
|
compress: {
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
global_defs: {
|
global_defs: {
|
||||||
@@ -670,44 +673,47 @@ Other options:
|
|||||||
|
|
||||||
##### mangle
|
##### mangle
|
||||||
|
|
||||||
- `reserved` - pass an array of identifiers that should be excluded from mangling
|
- `reserved` - pass an array of identifiers that should be excluded from mangling
|
||||||
|
|
||||||
- `toplevel` — mangle names declared in the toplevel scope (disabled by
|
- `toplevel` — mangle names declared in the toplevel scope (disabled by
|
||||||
default).
|
default).
|
||||||
|
|
||||||
- `eval` — mangle names visible in scopes where eval or with are used
|
- `eval` — mangle names visible in scopes where eval or with are used
|
||||||
(disabled by default).
|
(disabled by default).
|
||||||
|
|
||||||
- `keep_fnames` -- default `false`. Pass `true` to not mangle
|
- `keep_fnames` -- default `false`. Pass `true` to not mangle
|
||||||
function names. Useful for code relying on `Function.prototype.name`.
|
function names. Useful for code relying on `Function.prototype.name`.
|
||||||
See also: the `keep_fnames` [compress option](#compressor-options).
|
See also: the `keep_fnames` [compress option](#compressor-options).
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
//tst.js
|
// test.js
|
||||||
var globalVar;
|
var globalVar;
|
||||||
function funcName(firstLongName, anotherLongName)
|
function funcName(firstLongName, anotherLongName)
|
||||||
{
|
{
|
||||||
var myVariable = firstLongName + anotherLongName;
|
var myVariable = firstLongName + anotherLongName;
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
```javascript
|
||||||
|
var code = fs.readFileSync("test.js", "utf8");
|
||||||
|
|
||||||
UglifyJS.minify("tst.js").code;
|
UglifyJS.minify(code).code;
|
||||||
// 'function funcName(a,n){}var globalVar;'
|
// 'function funcName(a,n){}var globalVar;'
|
||||||
|
|
||||||
UglifyJS.minify("tst.js", { mangle: { reserved: ['firstLongName'] } }).code;
|
UglifyJS.minify(code, { mangle: { reserved: ['firstLongName'] } }).code;
|
||||||
// 'function funcName(firstLongName,a){}var globalVar;'
|
// 'function funcName(firstLongName,a){}var globalVar;'
|
||||||
|
|
||||||
UglifyJS.minify("tst.js", { mangle: { toplevel: true } }).code;
|
UglifyJS.minify(code, { mangle: { toplevel: true } }).code;
|
||||||
// 'function n(n,a){}var a;'
|
// 'function n(n,a){}var a;'
|
||||||
```
|
```
|
||||||
|
|
||||||
##### mangle.properties options
|
##### mangle.properties options
|
||||||
|
|
||||||
- `regex` — Pass a RegExp to only mangle certain names
|
- `regex` — Pass a RegExp to only mangle certain names
|
||||||
- `keep_quoted` — Only mangle unquoted property names
|
- `keep_quoted` — Only mangle unquoted property names
|
||||||
- `debug` — Mangle names with the original name still present. Defaults to `false`.
|
- `debug` — Mangle names with the original name still present. Defaults to `false`.
|
||||||
Pass an empty string to enable, or a non-empty string to set the suffix.
|
Pass an empty string to enable, or a non-empty string to set the suffix.
|
||||||
|
|
||||||
[acorn]: https://github.com/ternjs/acorn
|
[acorn]: https://github.com/ternjs/acorn
|
||||||
[sm-spec]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k
|
[sm-spec]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k
|
||||||
|
|||||||
Reference in New Issue
Block a user