Gulp为多个html页面编译手柄
Gulp-compile-handlebars for multiple html pages?
到目前为止,我只有两个gullow任务,例如gulp.task('handlebars-index')
和gulp.task('handlebars-about')
。以下是文档中的代码,https://www.npmjs.org/package/gulp-compile-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.handlers,然后编译它并创建了一个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'));
以上显然是行不通的。
Gulp rename还采用了一个函数,在该函数中,您只能更改部分路径。
return gulp.src('src/*.handlebars')
.pipe(handlebars(templateData, options))
.pipe(rename(function(path) {
path.extname = '.html';
}))
.pipe(gulp.dest('dist'));
https://github.com/hparra/gulp-rename#usage
相关文章:
- 是否可以使用有角度的HTML文档进行$编译
- 使用Gulp手柄部分编译为单个HTML文件
- AngularJS:带有HTML和angular表达式的指令;编译”;具有外部范围的内容
- 如何在编译时更新yeoman angular中的html路径
- 如何用一些已编译的HTML替换元素的值
- 如何将从GWT编译的JS添加/访问到另一个外部HTML / JS项目中
- 如何使用HtmlWebpackPlugin将已编译的Stylus捆绑包注入html文件
- Angularjs$编译输入html或元素
- 使用grunt预编译服务器端html模板
- AngularJs:抓取编译后的html并设置到工具提示中
- 编译角度代码以便能够执行内部html操作
- 我该如何访问由gullow灰质插件创建的数据对象(当使用nunjucks编译html文件时)
- '吞玉;没有工作或将jade编译为html
- 加载HTML后编译JS指令
- 使用javascript编译html并将其转储到文件中
- 使用来自我的控制器的数据编译 html 模板
- VueJS在内联模板组件中重新编译HTML
- 在Angular中编译HTML字符串模板
- 部分更新后,如何在ng-app作用域外编译html
- AngularJS指令:如何在promise之后编译html