How to use uglify-js - 10 common examples

To help you get started, we’ve selected a few uglify-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gflarity / response / test_old / node_modules / tap / node_modules / runforcover / node_modules / bunker / node_modules / burrito / node_modules / uglify-js / tmp / instrument2.js View on Github external
function instrument(code) {
        var ast = jsp.parse(code, false, true); // true for the third arg specifies that we want
                                                // to have start/end tokens embedded in the
                                                // statements
        var w = pro.ast_walker();

        function trace (line, comment) {
                var code = pro.gen_code(line, { beautify: true });
                var data = line[0]

                var args = []
                if (!comment) comment = ""
                if (typeof data === "object") {
                        code = code.split(/\n/).shift()
                        args = [ [ "string", data.toString() ],
                                 [ "string", code ],
                                 [ "num", data.start.line ],
                                 [ "num", data.start.col ],
                                 [ "num", data.end.line ],
                                 [ "num", data.end.col ]]
                } else {
github DefinitelyTyped / DefinitelyTyped / uglify-js / uglify-js-tests.ts View on Github external
var compressor = UglifyJS.Compressor({});
var compressed_ast = toplevel.transform(compressor);

compressed_ast.figure_out_scope();
compressed_ast.compute_char_frequency();
compressed_ast.mangle_names();

var stream = UglifyJS.OutputStream({});
compressed_ast.print(stream);
var code = stream.toString(); // this is your minified code

var code = compressed_ast.print_to_string({});

var source_map = UglifyJS.SourceMap({});
var stream = UglifyJS.OutputStream({
    //...
    source_map: source_map
});
compressed_ast.print(stream);

var code = stream.toString();
var map = source_map.toString(); // json output for your source map
github DefinitelyTyped / DefinitelyTyped / types / uglify-js / uglify-js-tests.ts View on Github external
var compressor = UglifyJS.Compressor({});
var compressed_ast = toplevel.transform(compressor);

compressed_ast.figure_out_scope();
compressed_ast.compute_char_frequency();
compressed_ast.mangle_names();

var stream = UglifyJS.OutputStream({});
compressed_ast.print(stream);
var code = stream.toString(); // this is your minified code

var code = compressed_ast.print_to_string({});

var source_map = UglifyJS.SourceMap({});
var stream = UglifyJS.OutputStream({
    //...
    source_map: source_map
});
compressed_ast.print(stream);

var code = stream.toString();
var map = source_map.toString(); // json output for your source map
github ctripcorp / moles-packer / lib / transform.js View on Github external
// 创建“函数”节点。
            var nodeFunction = new UglifyJS.AST_Function({
                argnames: funargs,
                body: node.body
            });

            // 创建“返回”节点。
            var nodeReturn = new UglifyJS.AST_Return({
                value: new UglifyJS.AST_SymbolRef({ name: 'module.exports' })
            });
            let nodeSemicolon = new UglifyJS.AST_Symbol({ name: ';' });
            nodeFunction.body.push(nodeSemicolon);
            nodeFunction.body.push(nodeReturn);

            // 创建“函数调用”节点。
            var nodeDefine = new UglifyJS.AST_Call({
                expression: new UglifyJS.AST_SymbolRef({ name: CONFIG.symbol.define }),
                args: [ nodeString, nodeArray, nodeFunction ]
            });

            return nodeDefine;
        }

        // 捕捉所有的 require() 调用。
        else if (node instanceof UglifyJS.AST_Call && node.expression.name == 'require') {
            // @debug 本段仅供调试
            if (node.start.value != 'require') {
                console.log(exporter.format(node));
                inform.exit('DEV ERROR No. 1');
            }

            // 获取 require 参数字符串值。
github telerik / kendo-ui-core / build / kendo-meta.js View on Github external
function U2_parse(code, options) {
    // if (options) {
    //     SYS.error("--- parsing " + options.filename);
    // }
    try {
        code = code.replace(/\r/g, ""); // 
        return U2.parse(code, options);
    } catch(ex) {
        if (ex instanceof U2.JS_Parse_Error) {
            console.log(options.filename);
            console.log(ex);
        }
    }
}
github irinc / ixf / build / build.js View on Github external
data = fs.readFileSync('scripts/ixf-utilities.js','utf8').replace("Y_Y_Y_Y", now.getFullYear()).replace('ixf.version = "X.X.X"','ixf.version = "' + versionNumber + '"').replace("X.X.X",versionNumber + " - " + now.getFullYear() + "/" + (now.getMonth()+1) + "/" + now.getDate()),
		outMin = fs.openSync('scripts/ixf-utilities.min.js','w'),
		index = data.indexOf("/*"), lastIndex = data.indexOf("*/",index),
		ast, minCode, buffer, comment;

	// Write permanent comment to minified file
	if(index != -1 && lastIndex != -1) {
		comment = data.substring(index,lastIndex+2);
		console.log(comment);
		buffer = new Buffer(comment + "\n");
		fs.writeSync(outMin, buffer, 0, buffer.length);
		data = data.substring(lastIndex+2);
	}

	//Minify the code
	ast = jsp.parse(data); // parse code and get the initial AST
	ast = pro.ast_mangle(ast); // get a new AST with mangled names
	ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
	minCode = pro.gen_code(ast); // compressed code here

	// Write minified code to file
	buffer = new Buffer(minCode+"\n");
	fs.writeSync(outMin, buffer, 0, buffer.length);
	fs.closeSync(outMin);
	console.log("  Output: scripts/ixf-utilities.min.js");

	if(callback)
		callback();
}
github youtify / youtify / make / generate_production_javascript.js View on Github external
function runUglify(mergedFile) {
    var ast;
    try {
        ast = jsp.parse(mergedFile); // parse code and get the initial AST
    } catch (e) {
        console.log('UglifyJS parse failed', e);
    }
    ast = pro.ast_mangle(ast); // get a new AST with mangled names
    ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
    return pro.gen_code(ast); // compressed code here
}
github youtify / youtify / make / generate_production_javascript.js View on Github external
function runUglify(mergedFile) {
    var ast;
    try {
        ast = jsp.parse(mergedFile); // parse code and get the initial AST
    } catch (e) {
        console.log('UglifyJS parse failed', e);
    }
    ast = pro.ast_mangle(ast); // get a new AST with mangled names
    ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
    return pro.gen_code(ast); // compressed code here
}
github irinc / ixf / build / build.js View on Github external
buffer = new Buffer(data);
		fs.writeSync(out, buffer, 0, buffer.length);

		// Write permanent comment to minified file
		index = data.indexOf("/*"), lastIndex = data.indexOf("*/",index);
		if(index != -1 && lastIndex != -1) {
			comment = data.substring(index,lastIndex+2);
			buffer = new Buffer(comment + "\n");
			fs.writeSync(outMin, buffer, 0, buffer.length);
			data = data.substring(lastIndex+2);
		}

		//Minify the code
		ast = jsp.parse(data); // parse code and get the initial AST
		ast = pro.ast_mangle(ast); // get a new AST with mangled names
		ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
		minCode = pro.gen_code(ast); // compressed code here

		// Write minified code to file
		buffer = new Buffer(minCode+";\n");
		fs.writeSync(outMin, buffer, 0, buffer.length);
	}
	fs.closeSync(out);
	fs.closeSync(outMin);
	console.log("  Output: scripts/ixf-plugins.js");
	console.log("  Output: scripts/ixf-plugins.min.js");

	if(callback)
		callback();
}
github bengourley / minj / lib / minj.js View on Github external
fs.readFile(jsPath, 'utf8', function (err, str) {
				if (err) {
					console.log(err);
					return error(err, next);
				}
				
				try {
					var ast = parser.parse(str);
					ast = uglifyer.ast_mangle(ast);
					ast = uglifyer.ast_squeeze(ast);
					fs.writeFile(minjPath, uglifyer.gen_code(ast), 'utf8', function (err) {
						next(err);
					});
				} catch (ex) {
					// Probably reached this because of invalid
					// syntax in js file. Revert back to serve original
					// -- let it error in the browser if need be.
					req.url = originalPath;
					next();
				}

			});