javascript - 使用 Ant 对多个文件运行单个命令

标签 javascript ant handlebars.js

我正在尝试使用 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/

相关文章:

javascript - 在 Angular 中创建资源

java - JUnit 和 Ant : How to show detailed error message on the screen?

ant - 无法在 eclipse 中运行 ANT 目标在开始时终止并指向 jdk\bin\javaw.exe

json - 在 JSON.stringify 中转义单引号

handlebars.js - 如何将 Handlebars 变量连接并传递到部分变量中

Ember.js:将模型传递到 View 中

javascript - 无法从 jquery 'this' 对象中找到 .attr

javascript - 测试用户点击 true 还是 false

java - Ant动态加载.properties文件

javascript - 基本模数理解有问题