Created
July 20, 2011 05:42
-
-
Save timoxley/1094412 to your computer and use it in GitHub Desktop.
Bundle all js files in ./scripts to ./application.js using Stitch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
argv = process.argv.slice(2) | |
stitch = require('stitch') | |
fs = require('fs') | |
mode = argv[0] || "DEV" | |
package = stitch.createPackage | |
paths: [__dirname + '/scripts'] | |
package.compile (err, source) -> | |
if mode == "PRODUCTION" | |
jsp = require("uglify-js").parser; | |
pro = require("uglify-js").uglify; | |
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 | |
final_code = pro.gen_code(ast); # compressed code here | |
source = final_code | |
fs.writeFile __dirname + '/application.js', source, (err) -> | |
if (err) | |
throw err | |
console.log 'Compiled application.js' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment