Skip to content

Instantly share code, notes, and snippets.

@timoxley
Created July 20, 2011 05:42
Show Gist options
  • Save timoxley/1094412 to your computer and use it in GitHub Desktop.
Save timoxley/1094412 to your computer and use it in GitHub Desktop.
Bundle all js files in ./scripts to ./application.js using Stitch
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