创建脚本以将Google Closure用于多个javascript文件 [英] Creating a script to use Google Closure for multiple javascript files
问题描述
我需要使用Google Closure compiler.jar来缩小我正在处理的大型项目。我有多个js文件,我想编译成一个game.min.js文件。我知道我可以使用以下内容:
I need to use the Google Closure compiler.jar to minify a huge project I am working on. I have multiple js files that I want to compile into a single game.min.js file. I know I can use the following:
java -jar compiler.jar --js file1.js --js file2.js --js etc, etc --js_output_file game.min.js
...但我有一个很多文件,据我所知,Closure不支持添加目录并查找驻留在该目录下的所有* .js文件。我笨拙的谷歌搜索没有给我任何工具,我可以用于工作(或任何无效的工作)。
...but I have a LOT of files and as I understand it Closure doesn't have support for adding a directory and finding all the *.js files residing under that directory. My fumbling google searches are not giving me any tools that I can use for the job (or nothing that works at any rate).
有没有人找到/使用/编写一个循环遍历目录的脚本,并将所有.js文件吐出到一个缩小的文件中?我对php,python等没有希望,所以任何帮助都非常感激。
Has anyone out there found / used / written a script that loops through a directory and spits out all the .js files into a single minified file? I am hopeless with php, python, etc, so any help greatly appreciated.
推荐答案
你可以使用ant自动使用闭包编译 r。
我在两个单独的步骤中进行,连接然后编译:
I do it in two separate steps, concatenation then compilation :
<concat destfile="src/somepath/app.concat.js">
<filelist dir="src/somepath">
<file name="a.js" />
<file name="b.js" />
<file name="c.js" />
<file name="d.js" />
</filelist>
</concat>
<jscomp compilationLevel="simple" warning="quiet" debug="false" output="src/app.min.js">
<sources dir="src/somepath">
<file name="app.concat.js" />
</sources>
</jscomp>
请注意文件的顺序很重要。这就是为什么你不能简单地将文件集传递给 jscomp
任务。
Be careful that the order of the files is important. That's why you can't simply pass a fileset to the jscomp
task.
这篇关于创建脚本以将Google Closure用于多个javascript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!