Skip to content

Instantly share code, notes, and snippets.

@timoxley
Created June 5, 2011 12:53
Show Gist options
  • Save timoxley/1008931 to your computer and use it in GitHub Desktop.
Save timoxley/1008931 to your computer and use it in GitHub Desktop.
compress 'stitched' code and cache as file
package.compile(function (err, source) {
var jsp = require("uglify-js").parser;
var pro = require("uglify-js").uglify;
var ast = jsp.parse(source); // 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
var final_code = pro.gen_code(ast); // compressed code here
fs.writeFile(__dirname + '/public/scripts/application.js', final_code, function (err) {
if (err) throw err;
util.puts('Compiled application.js');
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment