O'Reilly logo

Maintainable JavaScript by Nicholas C. Zakas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 20. Putting It Together

The preceding chapters about the build system focused on creating small pieces of a build system, creating a library of utilities that could easily be put together later. This chapter focuses on assembling the system into an end-to-end solution for your JavaScript. For your final system, you may have more complex functionality and may choose to use a bundled set of tasks such as Buildr, but there are still some common pieces of functionality that all build systems have.

Missing Pieces

Before putting together the build system, there are a couple of small steps that are missing. The first is the creation of the build directory. As this directory is transient (and won’t be checked in), the build system is responsible for its creation. The <mkdir> Ant task handles this easily:

<target name="init">
    <mkdir dir="${build.dir}"/>
</target>

The init target just does one thing: create the build directory so all the built files have a place to be put. It’s possible that other tasks, such as <concat>, may end up making this directory if it doesn’t already exist. However, it’s best to explicitly state each step of the build process to ensure that reordering of tasks or targets doesn’t cause errors.

The second missing piece is the cleanup of the build directory. In between builds, you want to remove all files and start over from scratch. The fastest way to do that is simply to delete the build directory using the <delete> task:

<target name="clean"> <delete dir="${build.dir}"/> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required