2

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>

2 Answers 2

1

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>
Sign up to request clarification or add additional context in comments.

Comments

-1
<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>

1 Comment

This doesn't solve the problem. The problem isn't that the OP didn't know how to compress files, it was that they wanted to compress and combine. All this answer does is compress using yui-ant instead of just directly using the yuicompressor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.