Skip to content

Instantly share code, notes, and snippets.

@mahemoff
Created August 22, 2011 18:22
Show Gist options
  • Save mahemoff/1163092 to your computer and use it in GitHub Desktop.
Save mahemoff/1163092 to your computer and use it in GitHub Desktop.
Kaffeine+Ugly in Express
var kaffeine = new (require("kaffeine"))();
app.register('.k', {
compile: function(str, options) {
return function(locals) { return uglify(kaffeine.compile(str)) };
}
});
function uglify(js) {
var jsp = require("uglify-js").parser;
var pro = require("uglify-js").uglify;
var orig_code = "... JS code here";
var ast = jsp.parse(js);
ast = pro.ast_mangle(ast);
ast = pro.ast_squeeze(ast);
return pro.gen_code(ast);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment