为了减少http请求,以及缩小js的体积,我们需要把游戏中用到的所有js打包成一个,在配置好jdk,ant,相应jar包后,这里的jar包是compiler.jar,google荣誉出品,配置build.xml如下
<?xml version="1.0"?>
<project name="Javascript compress project" basedir="." default="compile">
<!-- The classpath should be modified to the real closure compiler jar file path -->
<taskdef name="jscomp" classname="com.google.javascript.jscomp.ant.CompileTask" classpath="build/compiler.jar"/>
<target name="compile">
<jscomp compilationLevel="simple" warning="quiet"
debug="false" output="./game.min.js">
<!-- Uncomment the line below to enable sourcemap generation -->
<!--sourceMapOutputFile="./cocos2d-js-sourcemap" sourceMapFormat="V3"> -->
<sources dir="./">
<!-- You may need to modify the file name to the actual downloaded file name -->
<file name="cocos2d-js-v3.0.js"/>
<file name="resource.js"/>
<file name="Constant.js"/>
<file name="Map.js"/>
<!-- Put your own js files here, dependency order is also important -->
</sources>
</jscomp>
</target>
</project>
然后cd到相应的根目录,执行ant,十几秒输出文件game.min.js,大功告成。