Main /
JSMinimizationTaskAnother task we will eventually have to confront is to somehow automatically provide minimized versions of the .js files. Perhaps we could automatically create a file Foo_min.js for each Foo.js?
Resources
YUICompressor
Ant for YUICompressorhttps://github.com/parambirs/ant-yui-compressor looks useful. Here's how to build it: git clone https://github.com/parambirs/ant-yui-compressor.git cd ant-yui-compressor/ (cd lib;wget https://github.com/yui/yuicompressor/releases/download/v2.4.8/yuicompressor-2.4.8.jar) ant package This produces bash-3.2$ which ant /opt/local/bin/ant bash-3.2$ ls -l /opt/local/bin/ant lrwxr-xr-x 1 root admin 32 Nov 23 08:15 /opt/local/bin/ant -> ../share/java/apache-ant/bin/ant bash-3.2$ ls /opt/local/share/java/apache-ant/ CONTRIBUTORS etc lib bin fetch.xml patch.xml contributors.xml get-m2.xml bash-3.2$ sudo cp ~cxh/src/ant-yui-compressor/dist/ant-yui-compressor-taskdef-1.0.jar /opt/local/share/java/apache-ant/lib/ Password: bash-3.2$ See https://github.com/parambirs/ant-yui-compressor for how to use this. The disadvantage here is that we need to install this for ant to work. A better solution would be something that does not require modifying the local ant installation. Simple use of Ant and YUI CompressorWe could add a rule that would download yuicompressor and then use this rule: <target name="compress" description="compress the JS files"> <copy todir="temp/js" overwrite="yes"> <fileset dir="original/js"/> </copy> <apply executable="java" parallel="false" dest="temp/js"> <fileset dir="temp/js" includes="**/*.js" /> <arg line="-jar"/> <arg path="test_lib/yuicompressor-2.4.8.jar" /> <arg line="-v"/> <srcfile/> <arg line="-o"/> <mapper type="glob" from="*.js" to="*-min.js"/> <targetfile/> </apply> <move todir="original/js" overwrite="true"> <fileset dir="temp/js" /> <mapper type="glob" from="*-min.js" to="*.js"/> </move> </target> |