Getting ANT to work with YUI compressor on OS X


A while ago, a colleague introduced me to YUI Compressor. I was really amazed. I knew there were such kind of tools/applications out there, but never really bothered to find our which ones and how they work. So, I though, being a Mac user, that this should work on my mac as well… well… yes and no. Its not so easy getting it up and running, and I want to be able to run an ANT target in my PHP project to get this working.

So, I had some digging around to do, and ended up with my own little guide on how to get it working.

Installing the YUI Compressor

First off, I expect you to have a mac with OS X 10.8 or later and having MacPorts installed and updated. Then of course I expect you to have PHP, MySQL ect. up and running (not really required, but handy).

Then, we can get started.

First off, lets make sure we have wget installed:

Now, lets download the yui-compressor package:

and unzip it to /opt/local/bin

Now… lets test if YUI Compressor works, write:

and you should see something like:

Now, lets create a symbolic link

And now lets create the executable

Now, we need to give content to the executable, open it and add the code below:

Now, I know that sometimes these copy paste things go all wrong, so I uploaded the file I use here as well. See attachments.

Now, you should be able to compress some files. This is how you use the compressor:

Using ANT to compress

Now, this is something I LOVE, just because it makes it so easy. First off, I expect you to have ANT installed, if not.. run:

Using the script above, I wrote the following build.xml file:

Again, since copy-paste sometimes isn’t that nice in word-press… I uploaded my build.xml. See attachments.

So what does it do? Well… its checks the folder “protected/Javascripts” and uses all the .js files to create public_html/js/min.js. It does the same for css files, yet to and from an other folder. What it also does is it removes the current min.js and min.css files if they already exist. This is due to that we want complete fresh files.

So, I hope this helps you out! If so, Like the post please!






… and more, which I can’t remember. 🙁

Posted in 10.8, Apache, Apple, Free stuff, Mac, MacPorts, Objective-c, OSX, PHP, Shell scripts, Tools, Tutorials, Web, Websites Tagged with: , , , , , , , , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *