gulp-compile-handlebars 找不到部分
gulp-compile-handlebars not finding partials
我正在尝试遵循以下 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个小时了,我似乎无法在网上找到任何解决方案,所以这是我老实说放弃之前的最后一招。
你必须更换:
.pipe(handlebars(options))
作者:
.pipe(handlebars(null, options))
我正在尝试遵循以下 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个小时了,我似乎无法在网上找到任何解决方案,所以这是我老实说放弃之前的最后一招。
你必须更换:
.pipe(handlebars(options))
作者:
.pipe(handlebars(null, options))