我如何串连JavaScript文件合并成一个文件? [英] How do I concatenate JavaScript files into one file?
问题描述
我要创建我的网站编译JavaScript文件。对于开发我想preFER保持的JavaScript在单独的文件,只是作为我的自动化脚本的一部分的文件连接成一个,在它运行的COM pressor。
I want to create a compiled JavaScript file for my website. For development I would prefer to keep the JavaScript in separate files and just as part of my automated scripts concatenate the files into one and run the compressor over it.
我的问题是,如果我使用旧的DOS复制命令它也使在EOF标记该COM pressor抱怨:
My problem is that if I use the old DOS copy command it also puts in the EOF markers which the compressor complains about:
拷贝/ A * .js文件compiled.js / Y
copy /A *.js compiled.js /Y
什么是其他人在做什么?
What are other people doing?
推荐答案
我建议使用Apache Ant和YUI的COM pressor。
I recommend using Apache Ant and YUI Compressor.
http://yui.github.com/yuicom$p$pssor/
把这样的事情在Ant构建XML。
这将创建两个文件的application.js和应用程序min.js。
Put something like this in the Ant build xml. It will create two files, application.js and application-min.js.
<target name="concatenate" description="Concatenate all js files">
<concat destfile="build/application.js">
<fileset dir="src/js" includes="*.js" />
</concat>
</target>
<target name="compress" depends="concatenate" description="Compress application.js to application-min.js">
<apply executable="java" parallel="false">
<filelist dir="build" files="application.js" />
<arg line="-jar" />
<arg path="path/to/yuicompressor-2.4.2.jar" />
<srcfile />
<arg line="-o" />
<mapper type="glob" from="*.js" to="build/*-min.js" />
<targetfile />
</apply>
</target>
这篇关于我如何串连JavaScript文件合并成一个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!