Skip to content

Instantly share code, notes, and snippets.

@wesme1337
Created March 9, 2018 20:00
Show Gist options
  • Save wesme1337/f714eaa906661e0a09f5adbcbce4d868 to your computer and use it in GitHub Desktop.
Save wesme1337/f714eaa906661e0a09f5adbcbce4d868 to your computer and use it in GitHub Desktop.
Mura 7.0.* Combine, Compile, and Minify Handlebars Form Templates with Gulp
// Copy the root level templates folder [sitename]/js/src/templates into your theme [sitename]/includes/themes/[themename]/js/src/templates
// Modify the templates and run gulp inside the theme to combine all .hbs, compile, and minify the handlebars template
//Destinations
var destJS = 'compiled/js';
//Gulp plugins
var gulp = require('gulp'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
declare = require('gulp-declare'),
wrap = require('gulp-wrap'),
handlebars = require('gulp-handlebars');
//Handlebars compile task
gulp.task('hbsTemplates', function(){
gulp.src('js/theme/src/templates/*.hbs')
.pipe(handlebars())
.pipe(wrap('this.mura.Handlebars.template(<%= contents %>)'))
.pipe(declare({
namespace: 'mura.templates', // Mura's namespace for handlebars
noRedeclare: true, // Avoid duplicate declarations
}))
.pipe(uglify().on('error',function(e){
console.error('Error: '+e.cause.message+'<br>Filename: '+e.cause.filename+'<br>Line: '+e.cause.line);
}))
.pipe(concat('mura.handlebars.min.js'))
.pipe(gulp.dest(destJS));
});
gulp.task('default', 'hbsTemplates');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment