【发布时间】:2014-10-15 05:15:10
【问题描述】:
到目前为止,我只有两个 gulp 任务,例如 gulp.task('handlebars-index')、gulp.task('handlebars-about')。以下是文档中的代码,https://www.npmjs.org/package/gulp-compile-handlebars
我不确定如何处理两个 .handlebars 文件的任务。
var gulp = require('gulp');
var handlebars = require('gulp-compile-handlebars');
var rename = require('gulp-rename');
gulp.task('handlebars', function () {
var templateData = {
firstName: 'Kaanon'
},
options = {
ignorePartials: true, //ignores the unknown footer2 partial in the handlebars template, defaults to false
partials : {
footer : '<footer>the end</footer>'
},
batch : ['./src/partials'],
helpers : {
capitals : function(str){
return str.toUpperCase();
}
}
}
// here how do I add an index.html and say and about.html?
return gulp.src('src/index.handlebars')
.pipe(handlebars(templateData, options))
.pipe(rename('index.html'))
.pipe(gulp.dest('dist'));
});
你可以看到上面的任务基本上是获取 index.handlebars 然后编译它并创建一个 index.html 文件。
如果我添加了一系列车把文件,任务将如何知道如何创建 .html 版本?
return gulp.src(['src/index.handlebars','src/about.handlebars'])
.pipe(handlebars(templateData, options))
.pipe(rename('index.html'))
.pipe(rename('about.html'))
.pipe(gulp.dest('dist'));
上述方法显然行不通。
【问题讨论】:
标签: javascript gulp handlebars.js