如何预编译Handlebars模板并批量使用gulp-compile-handlebars转换为html

时间:2018-03-08 03:23:14

标签: javascript gulp handlebars.js precompiled-templates

我在服务器端使用express和node以及把手作为模板引擎。 现在从official documentation of gulp-compile-handlebars我开始了解把手模板的预编译技术,我正在做如下 -

const handlebars = require('gulp-compile-handlebars');
const rename = require('gulp-rename');
gulp.task('compile-handlebars', function () {
    var templateData = {
        data: 'Kaanon'
    },
    options = {
        batch : ['./views/partials'],
        helpers : {
            capitals : function(str){
                return str.toUpperCase();
            }
        }
    }

    return gulp.src('views/home.handlebars')
        .pipe(handlebars(templateData, options))
        .pipe(rename('home.html'))
        .pipe(gulp.dest('build'));
});

但是这允许我逐个预编译车把模板,而我想要一个将所有文件编译成该过程本身的html的过程。

例如SASS编译和转换为Css文件我这样做,

const sass = require('gulp-sass');
gulp.task('styles', function() {
    gulp.src('sass/*.scss')
        .pipe(sass(compile_config).on('error', sass.logError))
        .pipe(gulp.dest('./assets/css/'))
});

这会将所有sass文件转换为相应的css文件。

我想为我的车把模板做类似的事情。

附加我的目录结构以便更好地理解,

Directory structure

0 个答案:

没有答案
相关问题