Skip to content

Instantly share code, notes, and snippets.

@smithclay
Created October 24, 2012 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smithclay/3943043 to your computer and use it in GitHub Desktop.
Save smithclay/3943043 to your computer and use it in GitHub Desktop.
Example of a Minify Task using Jake
desc('Minify javascript.');
task('minify', function (params) {
var task = this, startTime = +new Date(), minifiedCount = 0,
targetPath = process.env.JS_BUILD_DIR || './';
debugFiles = barkeep.fileListRecursive(path.join(BUILD_GLOBALS.output, targetPath), BUILD_GLOBALS.debugExpr),
uglifyBin = path.join(__dirname, 'node_modules', 'uglify-js', 'bin', 'uglifyjs');
console.log('Minifying javascript files...'.green);
barkeep.directory(BUILD_GLOBALS.output); // Create build directory (if it doesn't exist).
async.forEach(debugFiles, function (fileName, callback) {
var extension = path.extname(fileName);
var minFile = fileName.replace('.debug' + extension, '.min' + extension);
var cmd = util.format('%s %s > %s', uglifyBin, fileName, minFile);
var child = exec(cmd, function (err) {
if (err) {
return callback(err);
}
callback(null);
});
}, function (err) {
console.log(util.format(' %s files minified.', debugFiles.length));
console.log(util.format(' total time: %s ms', +new Date() - startTime));
complete();
});
}, {async: true});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment