Skip to content

Instantly share code, notes, and snippets.

@thexodus
Last active August 29, 2015 14:15
Show Gist options
  • Save thexodus/889e5ad8e2eb3089e910 to your computer and use it in GitHub Desktop.
Save thexodus/889e5ad8e2eb3089e910 to your computer and use it in GitHub Desktop.
file minifier and zipper with node (css and javascript)
var fs = require('fs')
var zlib = require('zlib')
var gzip = zlib.createGzip();
var compressor = require(process.env['HOME'] + '/node_modules/node-minify');
new compressor.minify({
type: 'gcc',
fileIn: 'js/main.js',
fileOut: 'js/main.min.js',
callback: function(err, min){
console.log(err);
if(err == null){
console.log("Created minified file.")
console.log("Initializing creation of zip(gz) file....");
var inp = fs.createReadStream('js/main.min.js');
var out = fs.createWriteStream('js/main.js.gz');
inp.pipe(gzip).pipe(out);
console.log("Done creating zip(gz) files.");
} else{
console.log("Sorry, ecnountered problem while creating zip(gz) files.");
console.log(err);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment