使用Shrinksafe合并JS文件

问题描述:

亲爱的全部, 我需要使用Shrinksafe将一个文件夹内的所有JavaScript文件合并到一个文件中。 我正在使用以下ANT脚本。但是这不能正常工作。使用Shrinksafe合并JS文件

<!-- Merge the JS files in scripts folder to a single file--> 
<target name="mergegp-js"> 
    <echo message="Starting Merging"/>   
    <java fork="true" dir="${shrinksafe.util.path}/buildscripts" classname="org.mozilla.javascript.tools.shell.Main"> 
     <classpath> 
      <pathelement location="${shrinksafe.util.path}/shrinksafe/js.jar"/> 
      <pathelement location="${shrinksafe.util.path}/shrinksafe/shrinksafe.jar"/> 
      <pathelement path="${java.class.path}"/> 
     </classpath> 
     <arg value="build.js"/> 
     <arg value="${merged.gpstatic.folder}/test/scripts/*.js > tempMerged.js"/> 
    </java> 
    <echo message="js build successfull." /> 
</target> 

但是上面的脚本给了我下面的错误。

[java] js: "jslib/buildUtil.js", line 1168: exception from uncaught JavaScript throw: Malformed name/value pair: [C:/Test/scripts/*.js]. Format should be name=value 

有人可以请指导我解决这个问题。

+0

你有你的JSLinted JS代码?你确定它没有错误吗? – mrtom 2011-03-28 17:33:13

+0

jslib/buildUtils.js是Dojo Toolkit中的标准构建脚本。我可以证明它没有JavaScript语法错误。 – 2011-03-29 06:03:24

你确定这是有效的XML:

<arg value="${merged.gpstatic.folder}/test/scripts/*.js > tempMerged.js"/> 

build.js的参数应该是格式name=value。例如,profile=standard action=release。您需要更改参数的语法以匹配格式。所以经过

<arg value="build.js"/> 

行应该是这样的:

<arg value="profile=standard action=release" /> 
+0

感谢您的回复。是否可以在不使用build.js的情况下压缩文件? – Apps 2011-03-31 14:17:21

+1

如果你想使用Shrinksafe,''build.js''是实际工作的脚本。所以你需要使用它。但我认为您可以使用其他工具,例如简单的Ant脚本或Google Closure编译器。 – 2011-04-01 00:47:22