javascript - gulp-compile-handlebars 找不到部分

标签 javascript node.js gulp handlebars.js partials

我正在尝试遵循以下 gulp 插件的指南: https://www.npmjs.com/package/gulp-compile-handlebars

我正在使用的 gulp 函数如下,它由“gulp 页面”运行

gulp.task('pages', function () {

var options = {
    ignorePartials: true, //ignores the unknown footer2 partial in the handlebars template, defaults to false 
    partials : {
        footer : '<footer>the end</footer>'
    },
    batch : ['_hbs'],
    helpers : {
        capitals : function(str){
            return str.toUpperCase();
        }
    }
}
return gulp.src('_hbs/*.hbs')
    .pipe(handlebars(options))
    .pipe(rename(function (path) {
          path.extname = ".html"
        })
     )

    // Flatten structure
    //.pipe(flatten())

    // pretify html structure
   // .pipe(prettify({
   //   indent_size: 4
   // }))

    .pipe(gulp.dest('_hbs/'));

});

我有一个页面正在加载部分内容,如下所示:

{{> _common/header/header}}

我收到以下错误:

events.js:160
      throw er; // Unhandled 'error' event
      ^
Error: **The partial _common/header/header could not be found**
    at Object.invokePartial (C:\wamp\www\developer\HTML_seed\node_module
s\handlebars\dist\cjs\handlebars\runtime.js:271:11)
    at Object.invokePartialWrapper [as invokePartial] (C:\wamp\www\devel
oper\HTML_seed\node_modules\handlebars\dist\cjs\handlebars\runtime.js:68:39)
    at Object.eval (eval at createFunctionContext (C:\wamp\www\developer
\HTML_seed\node_modules\handlebars\dist\cjs\handlebars\compiler\javascript-compi
ler.js:254:23), <anonymous>:5:31)
    at main (C:\wamp\www\developer\HTML_seed\node_modules\handlebars\dis
t\cjs\handlebars\runtime.js:173:32)
    at ret (C:\wamp\www\developer\HTML_seed\node_modules\handlebars\dist
\cjs\handlebars\runtime.js:176:12)
    at ret (C:\wamp\www\developer\HTML_seed\node_modules\handlebars\dist
\cjs\handlebars\compiler\compiler.js:525:21)
    at DestroyableTransform._transform (C:\wamp\www\developer\HTML_seed\
node_modules\gulp-compile-handlebars\index.js:131:31)
    at DestroyableTransform.Transform._read (C:\wamp\www\developer\HTML_
seed\node_modules\gulp-compile-handlebars\node_modules\readable-stream\lib\_stre
am_transform.js:184:10)
    at DestroyableTransform.Transform._write (C:\wamp\www\developer\HTML
_seed\node_modules\gulp-compile-handlebars\node_modules\readable-stream\lib\_str
eam_transform.js:172:12)
    at doWrite (C:\wamp\www\developer\HTML_seed\node_modules\gulp-compil
e-handlebars\node_modules\readable-stream\lib\_stream_writable.js:237:10)

现在已经快 6 个小时了,我似乎无法在网络上的任何地方找到解决方案,所以这是我诚实放弃之前的最后手段。

最佳答案

您必须更换:

    .pipe(handlebars(options))

作者:

    .pipe(handlebars(null, options))

关于javascript - gulp-compile-handlebars 找不到部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41231790/

相关文章:

javascript - "Property description must be an object"错误

Node.js http 服务器 : what happens to the unread body of the POST request?

javascript - 使用闭包委托(delegate)运行回调

javascript - 无法读取 gulp-clean-css 插件中 originPosition 处未定义的属性 'line'

Gulp Watch 只运行一次

Javascript for循环直到 - 多个条件

javascript - 为什么在 Vue js 中尝试从 firebase 检索 token 时出现错误?

javascript - 如何使用 setInterval 函数更改幻灯片?

javascript - 准备部署express js应用程序,我应该担心哪些安全问题?

javascript - gulp useref 不能处理多个 html 文件