2016-02-18 73 views
2

我有一个模板文件夹,我有它下面的多个文件。 我想将所有这些模板编译成单个文件,以便我可以使用requireJS加载它。使用把手编译多个文件

我知道,我可以通过这样的构建工具咕噜,咕嘟咕嘟,早午餐等做到这一点

什么,我专门找了我是如何可以通过使用车把编译器命令行做到这一点。

我通过节点

npm install -g handlebars 

安装了编译器,但是,我可以只编译1文件在同一时间。

handlebars --amd templates/single-template.hbs -f compiled.js 

[我使用Windows OS]

回答

0

这里找到https://github.com/wycats/handlebars.js/issues/131

@echo off 
cls 
echo ------------------------------- 
:choice 
set /P c=Precompile every .html in this folder?[Y/N]? 
if /I "%c%" EQU "Y" goto :compile 
if /I "%c%" EQU "N" goto :end 
goto :choice 
:compile 
for %%f in (*.html) do (

     echo %%~nf 
     handlebars "%%~nf.html" -f "%%~nf.tmpl" -m 
) 
:end 
echo End of script 
pause 
exit 
1

这是那么容易,因为:

handlebars path/to/template/folder -f path/to/compiled/folder/all-templates-compiled.tpl.js