Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when precompiling all handlebars templates files in one js file

Here's my folder structure:

app
└───templates
    ├───templ1.hbs
    ├───templ2.hbs
    └───templ3.hbs

I want to compile (precompile) all templN.hbs handlebars template files in one templ.js file, but when i try to do it via console

$ handlebars *.hbs -f templ.js

compiling fails with this error

(...)\AppData\Roaming\npm\node_modules\handlebars\bin\handlebars:120
    throw err;
    ^
 Error: Unable to open template file "*.hbs"
    at (...)\AppData\Roaming\npm\node_modules\handlebars\dist\cjs\precompiler.js:107:25
    at FSReqWrap.oncomplete (fs.js:82:15)

What's the matter?

like image 930
gianmarcocalbi Avatar asked Jan 06 '23 23:01

gianmarcocalbi


1 Answers

After a bit of practice with Handlebars and its precompiler i found out the solution was as simple as stupid my question was.

First of all it's better to stay in the root folder, hence in my case stay in app folder. Then, to compile all .hbs templates, simply pass the entire ./handlebars folder as input to handlebars precompiler and specify the extension of templates he should look for:

$ handlebars ./templates -f templ.js --extension "hbs"

Everything should work fine.

For more precompiler's options see http://handlebarsjs.com/precompilation.html

like image 190
gianmarcocalbi Avatar answered Jan 08 '23 14:01

gianmarcocalbi