I'm looking to implement UglifyJS into my Ant build process to replace YUI Compressor. What are the basic steps to get started?
UglifyJS is a JavaScript parser/compressor/beautifier toolkit. It can be used to combine and minify JavaScript assets so that they require less HTTP requests and make your site load faster.
Minifying is just removing unnecessary white-space and redundant like comments and semicolons. And it can be reversed back when needed. Uglifying is transforming the code into an "unreadable" form by changing variable names, function names, etc, to hide the original content.
uglify-es is no longer maintained and uglify-js does not support ES6+.
After having installed uglifyjs with -g option:
npm install uglify-js -g
Use ant like that:
<exec dir="${build_dir}" executable="uglifyjs.cmd">
<arg line="-o jquery.min.js --unsafe -nc jquery.src.js"/>
</exec>
On Windows you use uglifyjs.cmd, and uglifyjs on linux. You can define a conditional property if you want to keep the build.xml cross-platform.
See https://github.com/mishoo/UglifyJS/#usage for all arguments
You can try this -> https://github.com/yuanyan/UglifyJS-java
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With