2

I have a templates folder and I have multiple files under it. I want to compile all these templates into a single file so that I can load it using requireJS.

I know that, I can do this via build tools like Grunt, Gulp, Brunch etc

What I am specifically looking for is how can I do this via command line using the handlebars compiler.

I installed the compiler via node

npm install -g handlebars

But, I am able to compile only 1 file at a time.

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

[I am using windows OS]

Anoop M D
  • 31
  • 5

2 Answers2

1

It's as easy as:

handlebars path/to/template/folder -f path/to/compiled/folder/all-templates-compiled.tpl.js
Zoltan.Tamasi
  • 1,382
  • 13
  • 26
0

found here 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
Daniel
  • 1,364
  • 1
  • 11
  • 18