Skip to content

Instantly share code, notes, and snippets.

@zerodi
Last active December 22, 2015 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerodi/fe76d433a53258aa45ee to your computer and use it in GitHub Desktop.
Save zerodi/fe76d433a53258aa45ee to your computer and use it in GitHub Desktop.
Gulp task to compile handlebars templates in amd
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
gulp.task('templates', function () {
gulp.src('templates/**/*.hbs')
.pipe($.handlebars({
handlebars: require('handlebars')
}))
.pipe($.wrap('template(<%= contents %>)'))
.pipe($.declare({
root: 'templates',
noRedeclare: true
}))
.pipe($.concat('templates.amd.js'))
.pipe($.wrap('define(["handlebars.runtime"], function(Handlebars) {\nHandlebars = Handlebars["default"]; var template = Handlebars.template,templates = Handlebars.templates = Handlebars.templates || {};\n <%= contents %>\nreturn templates;\n});'))
.pipe(gulp.dest('dist/'))
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment