Sunday, December 12, 2010

Automating Closure Compiler with Ant

In a previous post I talked about how to use Google's Closure Compiler to optimize and minify JavaScript files. Now I have shifted to a dual Ubuntu and Mac OS X development environment, I am determined to invest in a strong automatic build process. This is just as well, since compiled JavaScript is impossible to maintain or develop. Compiling JavaScript needs to be performed automatically and transparently.

I am building out my build scripts using Apache Ant. Ant is cross-platform compatible and is well supported in the Eclipse-based Aptana and Pydev development environments. Automating the JavaScript compilation using Ant proved a bit troublesome.

In Ant you use the Apply Task to run executable programs. Running Closure Compiler using the Apply task for each JavaScript file was the first hurdle, but Apply has obvious support for passing a FileSet to determine what those files would be. The bigger challenge was working out how to specify the input and output files using redirection.

My task was made a lot easier when I found a useful example of using Ant with JSMin as the last example on the documentation page, which is invoked in similar fashion to Closure Compiler. Modifying the example I came up with this Ant Target:

  <target name="-compilejs" depends="-copybuild"
description="(runs the closure js compiler against all javascript files to replace the files in the build folder">

<!-- modeled off example found at http://ant.apache.org/manual/Tasks/apply.html -->
<apply executable="java" parallel="false" failonerror="true" addsourcefile="false">
<arg value="-jar" />
<arg value="${path.assets.bin.closurecompiler}" />
<arg line="--warning_level QUIET" />
<arg line="--compilation_level SIMPLE_OPTIMIZATIONS" />
<fileset dir="${path.assets.src}" includes="**/*.js" />
<redirector>
<inputmapper type="glob" from="*.js" to="${path.assets.src}/*.js" />
<outputmapper type="glob" from="*.js" to="${path.build.src}/*.js" />
</redirector>
</apply>
</target>
This isn't perfect. This approach always compiles all of the JavaScript files, even when they have not been altered. and JavaScript compilation with Closure Compiler is currently the longest running activity of my build. I will be trying to tweak Apply invocation to get this fixed.

The other problem is the suppression of warnings. Warnings appear inline in the output JavaScript, which breaks the JavaScript file but does not fail the build, which is what I would prefer. I am wondering if I redirect the error output and check its contents and manually fail the build whether that will catch the problem, at which point I can remove the (dangerous) suppression of warnings.

I will let you know when I surmount these problems, but if you have any thoughts let me know. I will also go into more detail about the rest of my build process - specifically as it applies to Google App Engine, which is probably the more unique aspect, and therefore, most useful.

11 comments:

  1. Thanks Ben Davies, your blog is very interesting and useful, helped us very much on Google App Engine knowledges. I write a blog post for your blog, http://www.haulynjason.net/2010/12/ben-daviess-learning-technical-stuff.html I hope you like it.

    ReplyDelete
  2. I have created maven plugin https://github.com/aravinds03/minify-maven-plugin to listen for any file changes and generate minifed js automatically.

    ReplyDelete
  3. This one is an excellent way to improve and minify JavaScript files. Above example is very effective to understand the process of function. event planning applications for ipad

    ReplyDelete
  4. What people really do not often discover how to state is usually it is is not for one machine available kind of functionality, it to do this on an easy to use timepieces, it desires to accomplish this nicely. As soon as consumers scream that her merchandise, that is certainly what precisely they can be expressing http://www.hotreplicaonline.com. People anticipate perfect reliability plus practical operation. Typically the looks after as a firm really does therefore clearly since the device streamlines calculating in to a realistic list of curated guidelines. All the different watches will not invent whatever unique, it again purely enhanced accessibly to help functions plenty of people would not discover how to, or recommended do not usage in advance of. More than likely as telephones offer appropriate time to boot along with you could demand him or her anyways. All the plants from designer watches now we have, which includes programs out of good sized vendors just like manner, in addition to reduced varieties that include many others, suffer the pain of becoming difficult to rely on along with demoralizing. Complete these are offered? Without a doubt. Accomplish these reliably url to the looks after and also other products while offering your logical user interface and also frequently undertaking the things you expect those to do? Hardly any. The amount of suckiness fluctuates no doubt, yet none of them work regularly as vital. You can not responsibility these kind of enterprising suppliers intended for making the effort. Everybody wishing to manage to get thier 12 inches in the gate to generate shoppers couple its list utilizing watches. Also, they are trying to puzzle out just what it is actually persons who wear Rolex running watches want to serve with each other. Lord bless them all towards the, but next to nothing offered being a advanced hooked up look at ought to get the interest from the popular at the moment. Any different watches including a gasoline or diesel in order to connect towards the external community always. Most of us surely have wrist watches that could go to manner. However they happen to be sometimes hideously unsightly and / or have got ineffective variety life. What exactly My group is seeking to state is certainly that accomplishment associated with wearable computer systems for instance wristwatches is actually immediately connected to just about anything we can muster upward regarding next creation battery technological innovation. On the other hand, we have to participate in matches, and even we need to innovate. When one particular close of the technological know-how sector researches the right way to appear by means of cutting edge power packs, several other ends may generate items seriously looking ahead to these batteries to reach. The very first fine running watches only will possibly be replacements.

    ReplyDelete
  5. I am truly dazzled with this blog! Exceptionally clear clarification of issues is given and it is available to everybody. keep it up. Let make your blogs more plentiful on instagram with site profile picture

    ReplyDelete
  6. thanks for creating marvelous content and providing us the best knowledge download now spectrasonics bundle here https://vst-torrents.net/spectrasonics-omnisphere-crack/

    ReplyDelete
  7. Adobe Premiere Rush Crack With this all-in-one app for creating and sharing videos online, you can provide your channels with a steady stream of cool content – quickly and easily.
    Little Alterboy Crack
    IK Multimedia Sampletank Mac Crack
    Pro Evolution Soccer 2021 PC Game Download

    ReplyDelete
  8. Nice information. I’ve bookmarked your site, and I’m adding your RSS feeds to my Google account to get updates instantly. AnyMP4 Video Converter Crack

    ReplyDelete
  9. Thank you a bunch for sharing this with all of us you actually realize what you are talking about! Bookmarked.
    Ableton Live Suite Crack

    ReplyDelete
  10. 7
    Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!
    ABLETON LIVE SUITE CRACK

    ReplyDelete