How to use uglify-js

Comprehensive uglify-js code examples:

How to use uglify-js.parser:

7
8
9
10
11
12
13
14
15
16
17
18
19
var fs = require('fs');


var util = require('util');


var uglify = require("uglify-js");
var jsp = uglify.parser;
var pro = uglify.uglify;


var spawn = require('child_process').spawn;

How to use uglify-js.parse:

94
95
96
97
98
99
100
101
102
deob_cfg = defaults(deob_cfg, DEFAULT_CONFIG);
fs.readFile(inputFile,'utf-8', function(err, content) {
    if(err)
        throw err;
    
    var topLevel, ast = U2.parse(content, {
        filename: inputFile,
        topLevel: topLevel
    });

How to use uglify-js.uglify:

2
3
4
5
6
7
8
9
10
11
12
13


global.sys = require(/^v0\.[012]/.test(process.version) ? "sys" : "util");
var fs = require("fs");
var uglify = require("uglify-js"), // symlink ~/.node_libraries/uglify-js.js to ../uglify-js.js
    jsp = uglify.parser,
    pro = uglify.uglify;


var options = {
        ast: false,
        mangle: true,

How to use uglify-js.tokenizer:

156
157
158
159
160
161
162
163
164
165

var orig_code = fs.readFileSync(projectFile('js/' + filename), 'utf8');
var ast = pro.ast_squeeze(pro.ast_mangle(jsp.parse(orig_code))); // parse, mangle, and compress AST

// grab copyright/license comments if present
var tok = jsp.tokenizer(orig_code), c;
c = tok();
var copyright = show_copyright(c.comments_before);

// join copyright, minified code, and a semicolon (uglify strips them)

How to use uglify-js.minify:

94
95
96
97
98
99
100
101
102
103
		dash = "loadNgModules(" + templatePathArr[count] + " , " + controllerPathArr[count] + ", true)"
		count++
		return dash
	}))
} else {
	pluginContent = uglifyjs.minify(pluginContent)
}

if (manifest.renderer.dependencies) {
	manifest.renderer.dependencies.forEach(function (obj, i) {