YUI Compressor and NAnt
February 21st, 2010
I have been working on creating a DotNetNuke Skin for AthleticHost.com. In order to simplify deployment of the skin I wanted to add it as an extension to DNN rather that upload it via FTP. I choose to use NAnt to build the extension install file. In an effort to increase page performance I decided that the CSS and JavaScript files should be compressed and choose the YUI Compressor for the job.
I created two targets. One to minify the JavaScript and another for the CSS.
<target name="JavaScript.minify">
<foreach item="File" property="filename">
<in>
<items>
<include name="${temp.dir}/**/js/**/*.js"/>
</items>
</in>
<do>
<echo message="${filename}" />
<exec program="java" workingdir="${YUICompressor.dir}">
<arg value="-jar" />
<arg value="yuicompressor-2.4.2.jar" />
<arg value="--type" />
<arg value="js" />
<arg value="-o" />
<arg value="${filename}.min" />
<arg value="${filename}" />
</exec>
<move file="${filename}.min" tofile="${filename}" overwrite="true" />
</do>
</foreach>
</target>
<target name="Css.minify">
<foreach item="File" property="filename">
<in>
<items>
<include name="${temp.dir}/**/*.css"/>
</items>
</in>
<do>
<echo message="${filename}" />
<exec program="java" workingdir="${YUICompressor.dir}">
<arg value="-jar" />
<arg value="yuicompressor-2.4.2.jar" />
<arg value="--type" />
<arg value="css" />
<arg value="-o" />
<arg value="${filename}.min" />
<arg value="${filename}" />
</exec>
<move file="${filename}.min" tofile="${filename}" overwrite="true" />
</do>
</foreach>
</target>
The “Deploy” target then calls the “Css.minify” and “Javascript.minify”
<call target="JavaScript.minify" /> <call target="Css.minify" />
Download the full NAnt script.
Resouces:
http://developer.yahoo.com/yui/compressor/
http://nant.sourceforge.net/
