Want more? Subscribe to my free newsletter:

Setting Up A Build Process For JavaScript & CSS Files Using Ant (Screencast)

March 21, 2011

 

A well defined build process ensures that the output of your project is built in a consistent manner every time a new build is run. Today we're going to take a look at how you can setup your own Ant-powered build process using for client-side files (such as JavaScript and CSS).

You'll learn how to automate the validation of your scripts using JSLint (or JSHint), concatenate your files using sets of specific rules and finally minify both sets of your output for production use. You'll also learn some additional tips and tricks that can assist you in build file configuration along the way. I hope this screencast comes in useful.

Tools Required

The following are the tools you'll need for today's tutorial. Make sure you follow the Ant installation guide in case additional steps are required. OSX users may find this guide also useful.

The Screencast

Details: 720p resolution, 21:27m duration. Full-screen mode recommended

 

Watch Online MP4/Ogg Video Build.xml On GitHub

 

 

 

What If I Don't Have Time To Watch?

I understand that some of my readers don't have as much time to watch complete screencasts as others do. If you would like to learn how to setup a build process without watching the video, I recommend first installing all of the tools to your local system, then reading through the build.xml file I've put up on GitHub to learn about build file structure. You may need to spend a little additional time researching what particular attributes or tags do, but it will give you a foundation you can build on.

Screencast Notes

The purpose of this screencast is to introduce readers without a great deal of experience in setting up Ant builds with a primer in this area. So as to keep this screencast as widely applicable as possible, I've kept it server-side language and testing framework agnostic.

Once you understand the basics of setting up an Ant build, integrating additional steps for tasks like unit testing or switching out YUI Compressor for the closure library (or others) become significantly more trivial.I would like for more advanced users to bare this in mind when reviewing the structure of this video.

Erreta: Although the screencast mentions a client-side build process, what I mean to refer to is a build process which is used to validate and minify etc client-side type files (JS/CSS). Please bare in mind that this is a regular Ant build process and not one powered by JavaScript alone.

References/Further Reading

  • HTML5Boilerplate's build script is a great example of an expanded Ant build.xml file. You may also find their use of jpegtran and optipng (for image optimization) in the build of interest.
  • Mark Kolich has a useful post up about integrating Ant with Google's Closure compiler if you would rather dive right into setting that up for your build process.
  • If looking for a very simplified build script that just focuses on minification, L Corner's build sample may be worth looking at as well.
  • I personally like SyntaxHighlighter's build file which also demonstrates variable replacement and license file appending to your files in case you need to re-enforce your licensing conditions

Conclusions

And that's it!. Thanks once again to Aki Karkkainen for being the inspiration behind me recording this screencast. I know a few beginners have found his Ant file templates useful and hopefully this video will further encourage front-end devs to try out both Ant and the other tools listed in today's post. Build processes aren't as scary as they can sometimes appear ; )

If you found the screencast useful, please feel free to share it with your friends or colleagues by clicking the retweet or like buttons below.