Created
December 16, 2012 01:23
-
-
Save efeminella/4301937 to your computer and use it in GitHub Desktop.
Simple node program for js/css minification using yuicompressor
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
/* | |
* basic node program for js/css minification using yuicompressor | |
* | |
* Compress the file test.js: | |
* $ node compress.js ../js/test.js | |
* Created Minified File: ../js/test.min.js | |
* | |
* Compress the file test.css | |
* $ node compress.js ../css/test.css | |
* Created Minified File: ../css/test.min.css | |
* | |
*/ | |
var min = require('yuicompressor'); | |
var fs = require('fs'); | |
var _minify = function(name, ext, content) { | |
min.compress( content, { | |
'charset' :'utf8' | |
, 'type' : ext | |
, 'nomunge' : true | |
}, function(err, data, extra) { | |
_writeFile(name.replace('.' + ext, '.min.' + ext), data) | |
}); | |
}; | |
var _writeFile = function(name, content) { | |
fs.writeFile(name, content, function (err) { | |
if (!err) { | |
console.log('Created Minified File: ' + name); | |
} else { | |
throw err; | |
} | |
}); | |
}; | |
var _readFile = function(options) { | |
fs.readFile(options.name, 'utf8', function(err, source) { | |
if (!err) { | |
_minify(options.name, options.ext, source); | |
} else { | |
throw err; | |
} | |
}); | |
}; | |
var arguments = function() { | |
var args = process.argv.splice(2); | |
return { | |
'name' : args[0] | |
, 'ext' : args.length > 1 ? args[1] : 'js' | |
} | |
}; | |
_readFile(arguments()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment