Automatically exported from code.google.com/p/yui-compressor-ant-task
Java
Latest commit ef47fd2 Apr 5, 2015 @sbuckle Adding .gitignore file
Permalink
Failed to load latest commit information.
lib Initial commit Feb 20, 2011
src Fixed indentation issues Oct 15, 2013
.gitignore Adding .gitignore file Apr 5, 2015
.hgignore Initial commit Feb 20, 2011
LICENSE.TXT Added support for compressing CSS files Oct 7, 2013
README.md Create README.md Apr 5, 2015
build.properties Initial commit Feb 20, 2011
build.xml Initial commit Feb 20, 2011

README.md

Introduction

This project provides a custom Ant task for compressing JavaScript and CSS files using YUI Compressor.

More information here: http://www.simonbuckle.com/2011/02/20/yui-compressor-ant-task/

Ant Task

The name of the Ant task is "yuicompressor" (see the example below). It supports the following attributes:

Attribute Required Default Value
linebreak No -1
munge No true
preserveAllSemiColons No false
disableOptimizations No false
verbose No false
todir Yes N/A

A full description of the attributes (apart from todir) can be found on the YUI Compressor site: http://developer.yahoo.com/yui/compressor/

It also expects two child elements: fileset and mapper. These are required elements. The first specifies the list of files to compress; the second prescribes how they should be saved once minimised.

To build it run: ant package.

Example

Here's an example build file that looks for all the JavaScript files in the test directory and minimises them:

    <taskdef resource="yuicompressor.tasks" classpath="dist/yuicompressor-taskdef-1.0.jar"/>

    <target name="example">
            <yuicompressor linebreak="40" todir="/var/www">
                    <fileset dir="${basedir}/test" includes="*.js"/>
                    <mapper type="glob" from="*.js" to="*-min.js"/>
            </yuicompressor>
    </target>

Save the file as build.example.xml in the root directory of the project. To run it, type the following: ant -lib lib/yuicompressor-2.4.2.jar -f build.example.xml.

(The task relies on YUI Compressor so this must be specified using the -lib option.)

Here's another example that compresses both CSS and JavaScript files:

    <taskdef resource="yuicompressor.tasks" classpath="dist/yuicompressor-taskdef-1.0.jar"/>

    <target name="example">
            <yuicompressor linebreak="40" todir="/var/www">
                    <fileset dir="${basedir}/test" includes="*.css,*.js"/>
                    <mapper>
                          <globmapper from="*.css" to="*-min.css"/>
                          <globmapper from="*.js" to="*-min.js"/>
                    </mapper>
            </yuicompressor>
    </target>