minor fixes to README.md
This commit is contained in:
71
README.md
71
README.md
@@ -224,9 +224,9 @@ separate step, different from variable name mangling. Pass
|
|||||||
`--mangle-props`. It will mangle all properties that are seen in some
|
`--mangle-props`. It will mangle all properties that are seen in some
|
||||||
object literal, or that are assigned to. For example:
|
object literal, or that are assigned to. For example:
|
||||||
|
|
||||||
```js
|
```javascript
|
||||||
var x = {
|
var x = {
|
||||||
foo: 1
|
foo: 1
|
||||||
};
|
};
|
||||||
|
|
||||||
x.bar = 2;
|
x.bar = 2;
|
||||||
@@ -255,10 +255,10 @@ mangled to the same name in all of them. For this, pass `--name-cache filename.
|
|||||||
and UglifyJS will maintain these mappings in a file which can then be reused.
|
and UglifyJS will maintain these mappings in a file which can then be reused.
|
||||||
It should be initially empty. Example:
|
It should be initially empty. Example:
|
||||||
|
|
||||||
```
|
```bash
|
||||||
rm -f /tmp/cache.json # start fresh
|
$ rm -f /tmp/cache.json # start fresh
|
||||||
uglifyjs file1.js file2.js --mangle-props --name-cache /tmp/cache.json -o part1.js
|
$ 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
|
$ 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
|
Now, `part1.js` and `part2.js` will be consistent with each other in terms
|
||||||
@@ -273,7 +273,7 @@ Using quoted property name (`o["foo"]`) reserves the property name (`foo`)
|
|||||||
so that it is not mangled throughout the entire script even when used in an
|
so that it is not mangled throughout the entire script even when used in an
|
||||||
unquoted style (`o.foo`). Example:
|
unquoted style (`o.foo`). Example:
|
||||||
|
|
||||||
```
|
```bash
|
||||||
$ echo 'var o={"foo":1, bar:3}; o.foo += o.bar; console.log(o.foo);' | uglifyjs --mangle-props keep_quoted -mc
|
$ echo 'var o={"foo":1, bar:3}; o.foo += o.bar; console.log(o.foo);' | uglifyjs --mangle-props keep_quoted -mc
|
||||||
var o={foo:1,a:3};o.foo+=o.a,console.log(o.foo);
|
var o={foo:1,a:3};o.foo+=o.a,console.log(o.foo);
|
||||||
```
|
```
|
||||||
@@ -314,8 +314,8 @@ console.log(result.error); // runtime error
|
|||||||
You can also compress multiple files:
|
You can also compress multiple files:
|
||||||
```javascript
|
```javascript
|
||||||
var result = UglifyJS.minify({
|
var result = UglifyJS.minify({
|
||||||
"file1.js": "var a = function() {};",
|
"file1.js": "var a = function() {};",
|
||||||
"file2.js": "var b = function() {};"
|
"file2.js": "var b = function() {};"
|
||||||
});
|
});
|
||||||
console.log(result.code);
|
console.log(result.code);
|
||||||
```
|
```
|
||||||
@@ -350,7 +350,7 @@ console.log(result.code);
|
|||||||
|
|
||||||
## Minify option structure
|
## Minify option structure
|
||||||
|
|
||||||
```
|
```javascript
|
||||||
{
|
{
|
||||||
warnings: false,
|
warnings: false,
|
||||||
parse: {
|
parse: {
|
||||||
@@ -362,9 +362,9 @@ console.log(result.code);
|
|||||||
mangle: {
|
mangle: {
|
||||||
// mangle options
|
// mangle options
|
||||||
|
|
||||||
properties: {
|
properties: {
|
||||||
// mangle property options
|
// mangle property options
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
// output options
|
// output options
|
||||||
@@ -382,10 +382,10 @@ console.log(result.code);
|
|||||||
To generate a source map:
|
To generate a source map:
|
||||||
```javascript
|
```javascript
|
||||||
var result = UglifyJS.minify({"file1.js": "var a = function() {};"}, {
|
var result = UglifyJS.minify({"file1.js": "var a = function() {};"}, {
|
||||||
sourceMap: {
|
sourceMap: {
|
||||||
filename: "out.js",
|
filename: "out.js",
|
||||||
url: "out.js.map"
|
url: "out.js.map"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.log(result.code); // minified output
|
console.log(result.code); // minified output
|
||||||
console.log(result.map); // source map
|
console.log(result.map); // source map
|
||||||
@@ -403,10 +403,10 @@ be appended to code.
|
|||||||
You can also specify sourceRoot property to be included in source map:
|
You can also specify sourceRoot property to be included in source map:
|
||||||
```javascript
|
```javascript
|
||||||
var result = UglifyJS.minify({"file1.js": "var a = function() {};"}, {
|
var result = UglifyJS.minify({"file1.js": "var a = function() {};"}, {
|
||||||
sourceMap: {
|
sourceMap: {
|
||||||
root: "http://example.com/src",
|
root: "http://example.com/src",
|
||||||
url: "out.js.map"
|
url: "out.js.map"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -414,10 +414,10 @@ If you're compressing compiled JavaScript and have a source map for it, you
|
|||||||
can use `sourceMap.content`:
|
can use `sourceMap.content`:
|
||||||
```javascript
|
```javascript
|
||||||
var result = UglifyJS.minify({"compiled.js": "compiled code"}, {
|
var result = UglifyJS.minify({"compiled.js": "compiled code"}, {
|
||||||
sourceMap: {
|
sourceMap: {
|
||||||
content: "content from compiled.js.map",
|
content: "content from compiled.js.map",
|
||||||
url: "minified.js.map"
|
url: "minified.js.map"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// same as before, it returns `code` and `map`
|
// same as before, it returns `code` and `map`
|
||||||
```
|
```
|
||||||
@@ -577,8 +577,7 @@ Examples:
|
|||||||
```javascript
|
```javascript
|
||||||
// test.js
|
// test.js
|
||||||
var globalVar;
|
var globalVar;
|
||||||
function funcName(firstLongName, anotherLongName)
|
function funcName(firstLongName, anotherLongName) {
|
||||||
{
|
|
||||||
var myVariable = firstLongName + anotherLongName;
|
var myVariable = firstLongName + anotherLongName;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -664,11 +663,11 @@ Note, however, that there might be situations where comments are lost. For
|
|||||||
example:
|
example:
|
||||||
```javascript
|
```javascript
|
||||||
function f() {
|
function f() {
|
||||||
/** @preserve Foo Bar */
|
/** @preserve Foo Bar */
|
||||||
function g() {
|
function g() {
|
||||||
// this function is never called
|
// this function is never called
|
||||||
}
|
}
|
||||||
return something();
|
return something();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -703,7 +702,7 @@ scope). For example if you pass `--define DEBUG=false` then, coupled with
|
|||||||
dead code removal UglifyJS will discard the following from the output:
|
dead code removal UglifyJS will discard the following from the output:
|
||||||
```javascript
|
```javascript
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
console.log("debug stuff");
|
console.log("debug stuff");
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -737,7 +736,7 @@ using `var` with `reduce_vars` (enabled by default) should suffice.
|
|||||||
You can also use conditional compilation via the programmatic API. With the difference that the
|
You can also use conditional compilation via the programmatic API. With the difference that the
|
||||||
property name is `global_defs` and is a compressor property:
|
property name is `global_defs` and is a compressor property:
|
||||||
|
|
||||||
```js
|
```javascript
|
||||||
var result = uglifyJS.minify(fs.readFileSync("input.js", "utf8"), {
|
var result = uglifyJS.minify(fs.readFileSync("input.js", "utf8"), {
|
||||||
compress: {
|
compress: {
|
||||||
dead_code: true,
|
dead_code: true,
|
||||||
@@ -749,7 +748,7 @@ var result = uglifyJS.minify(fs.readFileSync("input.js", "utf8"), {
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Using native Uglify AST with `minify()`
|
### Using native Uglify AST with `minify()`
|
||||||
```
|
```javascript
|
||||||
// example: parse only, produce native Uglify AST
|
// example: parse only, produce native Uglify AST
|
||||||
|
|
||||||
var result = UglifyJS.minify(code, {
|
var result = UglifyJS.minify(code, {
|
||||||
@@ -764,7 +763,7 @@ var result = UglifyJS.minify(code, {
|
|||||||
|
|
||||||
// result.ast contains native Uglify AST
|
// result.ast contains native Uglify AST
|
||||||
```
|
```
|
||||||
```
|
```javascript
|
||||||
// example: accept native Uglify AST input and then compress and mangle
|
// example: accept native Uglify AST input and then compress and mangle
|
||||||
// to produce both code and native AST.
|
// to produce both code and native AST.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user