Javascript 在一个js文件中预编译所有把手模板文件时出错

Javascript 在一个js文件中预编译所有把手模板文件时出错,javascript,npm,handlebars.js,template-engine,Javascript,Npm,Handlebars.js,Template Engine,以下是我的文件夹结构: app └───templates ├───templ1.hbs ├───templ2.hbs └───templ3.hbs 我想在一个temp.js文件中编译(预编译)所有tempn.hbs Handlebar模板文件,但当我试图通过控制台进行编译时 $ handlebars *.hbs -f templ.js 编译失败,出现此错误 (...)\AppData\Roaming\npm\node_modules\handlebars\bin\h

以下是我的文件夹结构:

app
└───templates
    ├───templ1.hbs
    ├───templ2.hbs
    └───templ3.hbs
我想在一个temp.js文件中编译(预编译)所有tempn.hbs Handlebar模板文件,但当我试图通过控制台进行编译时

$ 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)
出什么事了?

在对车把及其预编译器进行了一些练习后,我发现解决方案和我的问题一样简单

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

$ handlebars ./templates -f templ.js --extension "hbs"
一切都会好起来的


有关预编译器的更多选项,请参见

是否确保已将active directory更改为正确的文件夹?很可能是呕吐,因为它正在查找
temp1.hbs
,但您实际上是在
~/Desktop
或其他地方运行命令。@Titus当我从cmd运行该命令时,我在
app/templates/
文件夹中。事实上,使用
$handlebars temp1.hbs-f temp1.js
编译一个模板,比如temp1.hbs,效果很好。