繁体   English   中英

gulp-compile-handlebars未找到局部

[英]gulp-compile-handlebars not finding 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))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM