Handlebars plugin for gulp 3
First, install gulp-handlebars
as a development dependency:
npm install --save-dev gulp-handlebars
Then, add it to your gulpfile.js
:
var handlebars = require('gulp-handlebars');
gulp.task('templates', function(){
gulp.src(['client/templates/*.hbs'])
.pipe(handlebars({
outputType: 'node'
}))
.pipe(gulp.dest('build/templates/'));
});
gulp-declare can be used to compile templates for the browser. Just pipe the output of gulp-handlebars to gulp-declare:
var handlebars = require('gulp-handlebars');
var declare = require('gulp-declare');
gulp.task('templates', function(){
gulp.src(['client/templates/*.hbs'])
.pipe(handlebars())
.pipe(declare({
namespace: 'MyApp.templates'
}))
.pipe(concat('templates.js'))
.pipe(gulp.dest('build/js/'));
});
Type: String
Default: bare
The desired output type. One of the following:
node
- Produce Node modulesamd
- Produce AMD modulescommonjs
- Produce CommonJS modulesbare
- Return an unmolested function definition
Type: Boolean
Default: false
Whether to wrap compiled template functions in a call to Handlebars.template
.
Type: Object
Compiler options to pass to Handlebars.precompile()
.