首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多个html页面的编译工具栏?

多个html页面的编译工具栏?
EN

Stack Overflow用户
提问于 2014-10-14 15:23:25
回答 1查看 4K关注 0票数 2

到目前为止,我只有两个任务,例如gulp.task('handlebars-index')gulp.task('handlebars-about')。下面是docs,https://www.npmjs.org/package/gulp-compile-handlebars的代码

我不知道如何处理两个.handlebars文件的任务。

代码语言:javascript
复制
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版本?

代码语言:javascript
复制
    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'));

以上内容显然行不通。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-14 21:15:10

Gulp rename还接受一个函数,在该函数中,只能更改路径的一部分。

代码语言:javascript
复制
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

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26364489

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档