Handlebars编译空模板,而不在Gulp任务中运行数据

Handlebars编译空模板,而不在Gulp任务中运行数据,gulp,handlebars.js,gulp-compile-handlebars,Gulp,Handlebars.js,Gulp Compile Handlebars,我正在运行一个简单的“吞咽”任务,该任务旨在以特定语言呈现我的车把模板版本。语言数据存储在JSON文件中,我要求在gulp pipe任务中动态地将其存储在变量中,然后执行Handlebar任务 gulp.task('compilen', () => { var strings; return gulp.src('frontend/templates/*/*.hbs') .pipe(through.obj(function(file,enc,cb){ var p = parseP

我正在运行一个简单的“吞咽”任务,该任务旨在以特定语言呈现我的车把模板版本。语言数据存储在JSON文件中,我要求在gulp pipe任务中动态地将其存储在变量中,然后执行Handlebar任务

gulp.task('compilen', () => {
var strings;


return gulp.src('frontend/templates/*/*.hbs')
.pipe(through.obj(function(file,enc,cb){
    var p = parsePath(file.relative);

    strings = require('./frontend/templates/' + p.dirname+ '/locales/en.json');

    console.log(strings);

     cb(null,file);
}))
.pipe(handlebars(strings, options))
.pipe(rename(function(path){


    path.basename += "-en";
    path.extname = ".html";

}))
.pipe(gulp.dest('build'));

});
每当我运行
gulp
时,一切都会运行,它输出一个没有
字符串的文件。{{}}被删除,但没有实际数据,就好像字符串对象是空的一样,但事实并非如此,因为每当我用tap和console.log包装
handlebar
函数时,它们的值都在那里。。更奇怪的是,如果我要传递一个对象文本,则所有内容都正确呈现,而不是
strings
变量

下面是一个样例hbs模板和我的json文件

main.hbs

{{> header}}

<div>
  {{home.title}}
</div>
main.html输出

<div>

</div>
<div>

</div>

我通过使用文档底部的另一个插件
gulp data
引用解决了这个问题。我用
gulpdata
对象替换了.obj
中的
,它现在可以工作了。我一直在努力尝试用吞咽来做简单的事情,所以我的建议是远离它

<div>

</div>
<div>

</div>