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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With