javascript - Error when precompiling all handlebars templates files in one js file - Stack Overflow

Here's my folder structure:app└───templates├───templ1.hbs├───templ2.hbs└───templ3.hbsI want to pi

Here's my folder structure:

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

I want to pile (prepile) 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

piling 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\prepiler.js:107:25
    at FSReqWrap.onplete (fs.js:82:15)

What's the matter?

Here's my folder structure:

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

I want to pile (prepile) 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

piling 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\prepiler.js:107:25
    at FSReqWrap.onplete (fs.js:82:15)

What's the matter?

Share Improve this question asked Jun 2, 2016 at 20:36 gianmarcocalbigianmarcocalbi 3132 silver badges13 bronze badges 2
  • Did you make sure you've changed the active directory into the correct folder? Most likely it's barfing because it's looking for templ1.hbs but you're actually running the mand from ~/Desktop or something. – Titus Commented Jun 2, 2016 at 20:58
  • @Titus When I run that mand from cmd I'm in the app/templates/ folder. In fact piling a single template such as templ1.hbs with $ handlebars templ1.hbs -f templ1.js works fine. – gianmarcocalbi Commented Jun 3, 2016 at 9:51
Add a ment  | 

1 Answer 1

Reset to default 10

After a bit of practice with Handlebars and its prepiler 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 pile all .hbs templates, simply pass the entire ./handlebars folder as input to handlebars prepiler and specify the extension of templates he should look for:

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

Everything should work fine.

For more prepiler's options see http://handlebarsjs./prepilation.html

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744156200a4560872.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信