I am about to create an apache ant target that compresses all my .js files with gzip. For now I came up with the following:
<target name="compress-js" description="Compressed JS files">
<echo>Compressing JS files...</echo>
<apply executable="gzip" parallel="false">
<arg value="-c" />
<arg value="--best" />
<srcfile />
<arg value=">" />
<targetfile suffix=".${extension}" />
<fileset dir="${js.dir}" includes="**/*.js" />
<mapper type="identity" />
</apply>
<echo>OK!</echo>
</target>
Reading the files works correctly but the generated targetfile has the wrong path.
Given ${js.dir} is: /var/htdocs/js
and I start my ant target in some other directory the script above produces the following shell command:
gzip -c /var/htdocs/js/a/b/1.js > ./a/b/1.js
which is not correct. The targetfile should get the same absolute path as the sourcefile. I want it to produce the following line:
gzip -c /var/htdocs/js/a/b/1.js > /var/htdocs/js/a/b/1.js
Can someone tell me how to do this?
Use something like =
see Ant manual for tar task
Beside that there is also a wrapper task for the YUI Compressor Task, here’s some detailled description how to use it =
Compress JavaScript and CSS as Part of your Build Process