Compresses or 'minifies' JavaScript or CSS files using the Yahoo! UI Compressor library
Note: This task depends on external libraries not included in the Ant distribution.
Download the Yahoo! UI Compressor distribution and copy the yuicompressor-n.n.n.jar to $ANT_HOME/lib; ~/.ant/lib or the ant $CLASSPATH. Also take a copy of this antlib and place in the same location.
Utilise the antlib by referencing it:
<project name="compress-test" basedir="." default="all" xmlns:minify="antlib:org.apache.ant.js.minify">
Attribute | Description | Required |
type | The type of files to compress valid options are js or css |
YES |
charset | The character set encoding of the input file | NO [defaults to UTF-8 if not specified] |
linebreak | The column to break at in the output file | NO [defaults to never breaking lines] |
verbose | Sets the output of the task to display all warnings while minifying | NO [defaults to no] |
FileSets are used to select sets of files to copy.
<minify:yui.compressor verbose="true" outputPath="${outputPath}" linebreak="80" type="js"> <fileset dir="${testscript.dir}"> <include name="*.js"/> </fileset> </minify:yui.compressor>
Minifies all javascript files found in the fileset. In the output file lines are broken after 80 chars.