Created
May 15, 2013 22:24
-
-
Save itsjustcon/5587923 to your computer and use it in GitHub Desktop.
Packages UglifyJS into a nice, lightweight command-line tool for minifying JavaScript files.
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
// CREATED BY: | |
// Connor Grady on May 15, 2013 | |
// http://connorgrady.com/ | |
// USAGE: | |
// node minify myfile.js | |
// node minify file1.js file2.js file3.js | |
// OUTPUT: | |
// file1.js --> file1.min.js | |
var UglifyJS = require('uglify-js'), | |
fs = require('fs'), | |
path = require('path'), | |
Files = process.argv.splice(2); | |
Files.forEach(function (arg) { | |
// Check for .js | |
if (path.extname(arg) !== '.js') | |
throw 'ERROR: "'+arg+'" is not a .js file!'; | |
// Get absolute path for input & output files | |
var iF = path.join(__dirname, arg), | |
oF = path.join(__dirname, arg.substring(0,arg.length-3) + '.min.js' ), | |
min = UglifyJS.minify(iF); | |
fs.writeFile(oF,min.code,function (err){ | |
if (err) throw err; | |
console.log('MINIFIED: "'+path.basename(iF)+'" --> "'+path.basename(oF)+'"'); | |
}); | |
}); |
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
{ | |
"name": "UglifyJS-Command-Line", | |
"description": "Packages UglifyJS into a nice, lightweight command-line tool for minifying JavaScript files.", | |
"version": "1.0", | |
"dependencies": { | |
"uglify-js": "2.2.*" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment