【问题标题】:gulp-compile-handlebars not finding partialsgulp-compile-handlebars 找不到部分
【发布时间】:2016-12-20 09:17:35
【问题描述】:

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

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

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 个小时了,我似乎在网上找不到任何解决方案,所以这是我在诚实放弃之前的最后手段。

【问题讨论】:

    标签: javascript node.js gulp handlebars.js partials


    【解决方案1】:

    你必须替换:

        .pipe(handlebars(options))
    

    作者:

        .pipe(handlebars(null, options))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-10
      • 2023-03-21
      • 2017-02-02
      • 1970-01-01
      • 1970-01-01
      • 2022-01-03
      • 2017-06-24
      • 2015-11-19
      相关资源
      最近更新 更多