我正在使用gulp compileHandlebars编译我的handlebars模板,并使用json数据创建一个页面,效果非常好……问题是我想在子目录中嵌套我的handlebars模板,但是当我这么做的时候,批处理在我添加:**/*.handlebar到批处理路径后再也找不到这些模板了。如下所示:
gulp.task('compileHandlebars', function () {
delete require.cache[require.resolve('./src/layout.json')]
var buildSettings = require('./src/layout.json');
var templateData = buildSettings,
options = {
batch : ['./src/assets/templates/**/*.handlebars']
}
gulp.src('./src/index.handlebars')
.pipe(handlebars(templateData, options))
.pipe(rename('index.html'))
.pipe(cleanhtml())
.pipe(gulp.dest('./dist'))
.pipe(livereload());
});发布于 2017-04-27 04:50:40
npm上docs说批处理需要一个文件路径数组,但这个示例显示了一个具有目录路径的数组。您的示例使用的是blob语法,该语法将不起作用。看起来批处理也不会递归地查看子目录...因此,我认为您必须创建一个数组,其中包含每个handlebars文件的父目录路径。
我知道这是件很糟糕的事。但是,您可以使用gulp-filenames自动化检索handlebar文件路径的过程,并从每个路径中切下文件名,以获得一个目录数组。
https://stackoverflow.com/questions/43566059
复制相似问题