There’s an updated version of this script in this blog post.
At work, we use TeamCity to automatically build and deploy to dev projects as we check in changes.
- Change the path in the referencing page to use the uncompressed file
- Make changes and test
- Re-compress the file
- Change the path in the referencing page back to the compressed file
- Check in changes
As you can imagine, this is slightly prone to error. It’s also an annoying manual step to do the compression.
There are two ways to install Ant Contrib – it can be installed directly into the Ant directory on the machine or the Jar can be stored locally with the script that uses it. If we install it inside Ant then every build agent and developer who wants to use the script will have to go and download it separately so we’ll use the second method and include it with the script (it’ll then go into source control and be available to everyone).
Go and download the latest release of Ant Contrib and put this under a build-lib (or whatever naming you want to use) folder of your project. We’re going to use relative paths to reference this from the build script.
You’re also going to need Google Closure so go and grab this from Google. Unzip the Jar and drop that into your build-lib folder.
If you want to run Ant scripts locally on Windows, you’ll need WinAnt.
Ant build file
Now create your build.xml Ant file in the root of your project. The lines with paths that need to be customised are highlighted.
You can now include this as a build task within TeamCity and it’ll loop through and compress every JS file it encounters.
Remember to rename the Ant Contrib JAR filename in your build file to match whatever version you’ve downloaded.
Some sample code is available on GitHub.