YUI压缩器将所有javascripts文件压缩为'min.js'

时间:2014-09-19 17:19:31

标签: javascript yui-compressor

我想将文件夹中的所有javascripts文件压缩到' min.js'但是,' *'似乎不起作用。以下是我的#build.xml'

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="compressScript" name="compress">

    <target name="compressScript">

        <exec executable="java" failonerror="true">
            <arg line="-jar yui/yuicompressor-2.4.8.jar --nomunge -o '.js$:.min.js' '*.js'"/>
        </exec>

    </target>

</project>

错误是这样的:

compressScript:
 [exec] java.io.FileNotFoundException: *.js (No such file or directory)
 [exec]     at java.io.FileInputStream.open(Native Method)
 [exec]     at java.io.FileInputStream.<init>(FileInputStream.java:106)
 [exec]     at java.io.FileInputStream.<init>(FileInputStream.java:66)
 [exec]     at com.yahoo.platform.yui.compressor.YUICompressor.main(YUICompressor.java:133)
 [exec]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 [exec]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 [exec]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 [exec]     at java.lang.reflect.Method.invoke(Method.java:597)
 [exec]     at com.yahoo.platform.yui.compressor.Bootstrap.main(Bootstrap.java:21)

如果我改变了&#39; *。js&#39;对于某个名称,例如&#39; example.js&#39;,它将exmaple.js压缩到同一文件夹中的example.min.js中。那么我该如何压缩该文件夹中的所有脚本呢?

1 个答案:

答案 0 :(得分:0)

我这样用过:

<apply executable="java" parallel="false">
        <fileset dir="${root}/js-no-console" includes="*.js"/>
        <arg line="-jar"/>
        <arg path="${root}/${tool.yuicompressor}"/>
        <srcfile/>
        <redirector alwayslog="true">
            <outputmapper type="glob" from="*.js" to="${root}/${js.min.dir}/*-min.js"/>
        </redirector>
    </apply>