Skip to content

Instantly share code, notes, and snippets.

@lukearmstrong
Created March 2, 2012 11:54
Show Gist options
  • Save lukearmstrong/1957982 to your computer and use it in GitHub Desktop.
Save lukearmstrong/1957982 to your computer and use it in GitHub Desktop.
Ant CSS/JS Compressor
<?xml version="1.0" ?>
<project default="js.minify" basedir=".">
<target name="load.properties">
<echo>Initialize Variables</echo>
<property name="public.path" value="httpdocs" />
<echo message="public.path: ${public.path}" />
<property name="yuiCompressor.path" value="includes/build/yuicompressor-2.4.6.jar" />
<echo message="yuiCompressor.path: ${yuiCompressor.path}" />
<property name="googleClosureCompiler.path" value="includes/build/google-closure-compiler-1346.jar" />
<echo message="googleClosureCompiler.path: ${googleClosureCompiler.path}" />
</target>
<target name="css.concatenate" depends="load.properties">
<echo>Concatenate CSS files: /css/_build/style.css</echo>
<concat destfile="${public.path}/css/_build/style.css" encoding="UTF-8" eol="lf" fixlastline="yes" outputencoding="UTF-8">
<filelist dir="${public.path}/css/boilerplate/" files="1-reset.css" />
<fileset dir="${public.path}/css/screen/">
<include name="*.css" />
<exclude name=".hgkeep" />
</fileset>
<filelist dir="${public.path}/css/boilerplate/" files="2-helpers.css" />
<filelist dir="${public.path}/css/boilerplate/" files="3-responsive.css" />
<fileset dir="${public.path}/css/responsive/">
<include name="*.css" />
<exclude name=".hgkeep" />
</fileset>
<filelist dir="${public.path}/css/boilerplate/" files="4-print.css" />
<fileset dir="${public.path}/css/print/">
<include name="*.css" />
<exclude name=".hgkeep" />
</fileset>
</concat>
</target>
<target name="css.minify" depends="css.concatenate">
<echo>Minify CSS using YUI Compressor: /css/_build/style.css => /css/_build/style.min.css</echo>
<apply executable="java" parallel="false">
<fileset dir="${public.path}/css/_build/" includes="style.css" />
<mapper type="glob" from="style.css" to="${public.path}/css/_build/style.min.css" />
<arg line="-jar" />
<arg path="${yuiCompressor.path}" />
<srcfile />
<arg line="-o" />
<targetfile />
</apply>
</target>
<target name="js.concatenate" depends="css.minify">
<echo>Concatenate JS files: /js/_build/scripts.js</echo>
<concat destfile="${public.path}/js/_build/scripts.js" encoding="UTF-8" eol="lf" fixlastline="yes" outputencoding="UTF-8">
<fileset dir="${public.path}/js/lib/">
<include name="*.js" />
<exclude name=".hgkeep" />
</fileset>
<fileset dir="${public.path}/js/run/">
<include name="*.js" />
<exclude name=".hgkeep" />
</fileset>
</concat>
</target>
<target name="js.minify" depends="js.concatenate">
<echo>Minify JavaScript using Google Closure Compiler: /js/_build/scripts.js => /js/_build/scripts.min.js</echo>
<apply executable="java" parallel="false">
<fileset dir="${public.path}/js/_build/" includes="scripts.js" />
<mapper type="glob" from="scripts.js" to="${public.path}/js/_build/scripts.min.js" />
<arg line="-jar" />
<arg path="${googleClosureCompiler.path}" />
<arg line="--js" />
<srcfile />
<arg line="--js_output_file" />
<targetfile />
</apply>
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment