Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use UglifyJS from an Ant build? [closed]

I'm looking to implement UglifyJS into my Ant build process to replace YUI Compressor. What are the basic steps to get started?

like image 617
cmcculloh Avatar asked Jun 16 '11 15:06

cmcculloh


People also ask

What is the use of UglifyJS?

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.

What is Uglify and minify?

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.

Does Uglify support ES6?

uglify-es is no longer maintained and uglify-js does not support ES6+.


2 Answers

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

like image 137
Tomap Avatar answered Sep 19 '22 02:09

Tomap


You can try this -> https://github.com/yuanyan/UglifyJS-java

like image 31
Zhong Wei Avatar answered Sep 18 '22 02:09

Zhong Wei