Skip to content

Instantly share code, notes, and snippets.

@zhang-ning
Last active December 29, 2015 13:19
Show Gist options
  • Save zhang-ning/7676248 to your computer and use it in GitHub Desktop.
Save zhang-ning/7676248 to your computer and use it in GitHub Desktop.
uglify
#!/usr/bin/env node
var fs = require("fs"),
uglify = require("uglify-js");
var filename = process.argv[2],
toplevel = uglify.parse(fs.readFileSync(filename, "utf8"), {filename: filename}),
output = uglify.OutputStream({ascii_only: true}),
compressor = uglify.Compressor(true),
warn = uglify.AST_Node.warn;
uglify.AST_Node.warn = function(s, o) {
if (o.msg === "Accidental global?" && o.name === "d3" && o.line === 1 && !o.col) return;
warn.apply(this, arguments);
};
toplevel.figure_out_scope();
toplevel.scope_warnings({
undeclared: false,
unreferenced: false,
assign_to_global: true,
func_arguments: false,
nested_defuns: false,
eval: false
});
toplevel = toplevel.transform(compressor);
toplevel.figure_out_scope();
toplevel.compute_char_frequency(true);
toplevel.mangle_names(true);
toplevel.print(output);
require("util").print(output.get())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment