Anoop M D
Anoop M D

Reputation: 101

Compile multiple files using Handlebars

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]

Upvotes: 2

Views: 2856

Answers (2)

Zoltan.Tamasi
Zoltan.Tamasi

Reputation: 1391

It's as easy as:

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

Upvotes: 1

Daniel
Daniel

Reputation: 1402

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

Upvotes: 0

Related Questions