If you are using nodejs try uglify-js
In Ubuntu 12.04, if you have already installed nodejs, you can install uglify with:
sudo npm install -g uglify-js
And then get the following options:
uglifyjs -h
So, if I have the source file foo.js that looks like this:
// foo.js -- minified function foo(bar,baz){console.log("something something");return true;}
I can decorate it like this:
uglifyjs foo.js --beautify --output cutefoo.js
uglify uses spaces for indentation by default, so if I want to convert 4-space indentation to tabs, I can run it through unexpand that Ubuntu 12.04 comes with:
unexpand --tabs=4 cutefoo.js > cuterfoo.js
Or you can do it all in one go:
uglifyjs foo.js --beautify | unexpand --tabs=4 > cutestfoo.js
You can learn more about unpand here.
so after all this I end up with a file that looks like this:
function foo(bar, baz) { console.log("something something"); return true; }
update 2016-06-07
It seems that supporting uglify-js is now working on version 2 , although the installation is the same.
erapert May 12 '13 at 23:55 2013-05-12 23:55
source share