多个html页面的gulp-compile-handlebars?

Mic*_*bry 2 javascript handlebars.js gulp

截至目前,我只有两个gulp任务,ex 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'));
});
Run Code Online (Sandbox Code Playgroud)

你可以看到上面的任务基本上采取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'));
Run Code Online (Sandbox Code Playgroud)

以上情况不会明显起作用.

Hei*_*kki 8

Gulp-rename还具有一个功能,您只能更改路径的一部分.

return gulp.src('src/*.handlebars')
    .pipe(handlebars(templateData, options))
    .pipe(rename(function(path) {
        path.extname = '.html';
    }))
    .pipe(gulp.dest('dist'));
Run Code Online (Sandbox Code Playgroud)

https://github.com/hparra/gulp-rename#usage