How to Precompile Handlebars templates and convert to html using gulp-compile-handlebars in batch

866 Views Asked by At

I am using express and node in server side and handlebars as templating engine. Now from the official documentation of gulp-compile-handlebars I came to know about pre-compiling technique of handlebars templates, which I am doing as below -

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'));
});

But this allows me to precompile the handlebar templates one by one, whereas I want a process which will compile all files to html in that process itself.

e.g SASS compilation and converting to Css files I am doing like this,

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/'))
});

This converts all sass files to respective css files.

I want a similar thing for my handlebar templates.

Attaching my directory structure for better understanding,

Directory structure

0

There are 0 best solutions below