使用ant打包js文件

为了减少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,大功告成。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值