我正在尝试使用 ant 将一堆 Handlebars 模板编译成一个编译文件。我有许多文件夹,每个文件夹包含大约 4 个模板,我想将它们全部编译到一个文件中。文件夹如下:
folder01
|- templates
|- f1_01.handlebars
|- f1_02.handlebars
|- f1_03.handlebars
|- f1_04.handlebars
folder02
|- templates
|- f2_01.handlebars
|- f2_02.handlebars
|- f2_03.handlebars
|- f2_04.handlebars
build.xml
我基本上想运行命令:
handlebars **/templates/*.handlebars -f compiled-templates.js
我尝试了以下方法,但它似乎只在输出 js 文件中包含 1 个文件。
<macrodef name="handlebars">
<attribute name="target"/>
<sequential>
<apply executable="${handlebars}" failonerror="false">
<fileset dir="." includes="**/templates/">
<include name="*.handlebars"/>
</fileset>
<arg value="-f compiled-templates.js"/>
</apply>
</sequential>
</macrodef>
此外,奇怪的是,输出文件以空格字符开头,我似乎无法摆脱它。任何帮助将不胜感激。
最佳答案
在 stackoverflow 上进行了大量搜索之后,更重要的是,阅读了文档后,我想出了这个有效的解决方案。
<echo level="info" message="Pre Compiling templates" />
<apply parallel="true" failonerror="true" executable="node">
<arg value="${webclient.dir.build}/node_modules/handlebars/bin/handlebars" />
<srcfile />
<fileset dir="${webclient}/app/templates" includes="**/*.handlebars"/>
<arg line="-f ${webclient}/app/templates/handlebars.templates.js -m -a" />
</apply>
关于javascript - 使用 Ant 对多个文件运行单个命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9671790/