Skip to content

Wu-Wu/gulp-handlebars

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gulp-handlebars NPM version Build status

Handlebars plugin for gulp 3

Usage

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

Compiling to a namespace for the browser

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

API

handlebars(options)

options.outputType

Type: String
Default: bare

The desired output type. One of the following:

  • node - Produce Node modules
  • amd - Produce AMD modules
  • commonjs - Produce CommonJS modules
  • bare - Return an unmolested function definition

options.wrapped

Type: Boolean
Default: false

Whether to wrap compiled template functions in a call to Handlebars.template.

options.compilerOptions

Type: Object

Compiler options to pass to Handlebars.precompile().

About

Handlebars plugin for gulp

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published