Saturday, 14 September 2013

Use Ant and Closure Compiler to compile files matching filename pattern?

Use Ant and Closure Compiler to compile files matching filename pattern?

I am working on a web project involving a lot of JavaScript and have
decided to split the JS files for better maintainability.
Here is a quick summary of the JavaScript files I have:
app.core.js
app.pages.all.js
app.pages.page_a.js
app.pages.page_b.js
app.pages.page_c.js
...
app.final.js
I need Closure Compiler to compile the JavaScript files in such a way that
app.core.js is compiled first, followed by app.pages.*.js, and finally
app.final.js.
This needs to be done twice, once to produce a pretty printed version for
development and debugging purposes (output file app.js) and once for a
minified version for production (output file app.min.js).
I understand I can use wildcards (from this article) to select files
matching a filename pattern, but am unsure how to use that in combination
with manually specified files to retain compilation order (necessary due
to dependencies).
Currently, the relevant section of my build.xml file looks like this:
<target name="js.core.compile">
<property name="js.dir" value="app/webroot/js" />
<jscomp compilationLevel="simple" debug="false"
output="${js.dir}\app.js" forceRecompile="true" prettyPrint="true">
<sources dir="${js.dir}">
<file name="app.core.js" />
<file name="app.pages.all.js" />
<file name="app.pages.page_a.js" />
<file name="app.pages.page_b.js" />
<file name="..." /> <!-- simplified for brevity -->
<file name="app.final.js" />
</sources>
</jscomp>
<jscomp compilationLevel="simple" debug="false"
output="${js.dir}\app.min.js" forceRecompile="true">
<sources dir="${js.dir}">
<file name="app.core.js" />
<file name="app.pages.all.js" />
<file name="app.pages.page_a.js" />
<file name="app.pages.page_b.js" />
<file name="..." /> <!-- simplified for brevity -->
<file name="app.final.js" />
</sources>
</jscomp>
</target>
My question in summary is:
How can I get Ant to select all the app.pages.x files automatically but
still retain the compilation order for app.core.js and app.final.js?
Is it possible to specify the just once as some form of variable (similar
to <property>)?

No comments:

Post a Comment