Skip to content

Latest commit

 

History

History
47 lines (33 loc) · 888 Bytes

2.3.5 ES6 +的JavaScript解析器和mangler compressor工具包.md

File metadata and controls

47 lines (33 loc) · 888 Bytes

2.3.5 ES6 +的JavaScript解析器和mangler compressor工具包

install

npm install terser -S

在命令行使用(Command line usage)

  • terser [input files] [options]
An example:

// example.js
var x = {
    baz_: 0,
    foo_: 1,
    calc: function() {
        return this.foo_ + this.baz_;
    }
};
x.bar_ = 2;
x["baz_"] = 3;
console.log(x.calc());
Mangle all properties (except for JavaScript builtins) (very unsafe):

$ terser example.js -c -m --mangle-props

API Reference (Node 环境)

var Terser = require("terser");

var code = "function add(first, second) { return first + second; }";
var result = Terser.minify(code);
console.log(result.error); // runtime error, or `undefined` if no error
console.log(result.code);  // minified output: function add(n,d){return n+d}

参考