How to use YUI Compressor in Ant build script for javascript

I have ANT script which compresses .js files into their own files, but i want to compress all .js files into one .js file.

How to make it work using below ANT script.

<echo message="Compressing Javascript files at location: ${build.root}/resources/js/*.js" />
<java jar="c:/dev/lib/yuicompressor-2.4.7/build/yuicompressor.jar" fork="true">
    <arg value="${build.root}/resources/js/*.js" /> <!-- input path for JS files -->
    <!--<arg value="-v" /> --><!-- Turn on verbose -->
    <arg value="-o" />
    <arg value="'.js$:.js'" />
    <arg value="${build.root}/resources/js/*.js" /> <!-- output path for JS files -->
    <classpath>
        <pathelement location="c:/dev/lib/yuicompressor-2.4.7/build/yuicompressor.jar"/>
    </classpath>
</java>

Answers:

Answer

After a long search I got solution, basically after yui compress i have to do concat on all compressed file.

Use :

    <concat destfile="build/*.js">
        <fileset dir="build/*" includes="*js" />
    </concat>
Answer
<target name="minify" description="Minifiy a set of files">
    <available file="build-lib/YUIAnt.jar" property="YUIANT_AVAILABLE" />
    <fail unless="YUIANT_AVAILABLE" message="Run jar target to generate the required task" />
    <taskdef name="yuicompress" classname="com.yahoo.platform.yui.compressor.YUICompressTask">
        <classpath>
            <pathelement path="build-lib/yuicompressor-2.4.2.jar" />
            <pathelement path="build-lib/YUIAnt.jar" />
        </classpath>
    </taskdef>
    <mkdir dir="dist\js" />
    <yuicompress linebreak="300" warn="false" munge="yes" preserveallsemicolons="true" outputfolder="${dist}">
        <fileset dir="WebRoot">
            <include name="**/*.js" />
            <exclude name="**/jquery.js" />
        </fileset>
    </yuicompress>
    <yuicompress linebreak="300" warn="false" munge="yes" preserveallsemicolons="true" outputfolder="${dist}">
        <fileset dir="WebRoot/">
            <include name="**/*.css" />
        </fileset>
    </yuicompress>
</target>

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.