gpt4 book ai didi

javascript - 在一个 js 文件中预编译所有 handlebars 模板文件时出错

转载 作者:搜寻专家 更新时间:2023-11-01 05:04:05 26 4
gpt4 key购买 nike

这是我的文件夹结构:

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

我想在一个 templ.js 文件中编译(预编译)所有 templN.hbs handlebars 模板文件,但是当我尝试通过控制台执行此操作时

$ handlebars *.hbs -f templ.js

编译失败并出现此错误

(...)\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)

怎么了?

最佳答案

在使用 Handlebars 及其预编译器进行一些练习后,我发现解决方案非常简单,我的问题很愚蠢。

首先,最好保留在根文件夹中,因此在我的例子中,保留在 app 文件夹中。然后,要编译所有 .hbs 模板,只需将整个 ./handlebars 文件夹作为输入传递给 handlebars 预编译器,并指定他应该查找的模板扩展名:

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

一切正常。

有关预编译器的更多选项,请参阅 http://handlebarsjs.com/precompilation.html

关于javascript - 在一个 js 文件中预编译所有 handlebars 模板文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37601649/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com