Compiles Jade templates single file containing template functions. For projects small enough that they don't require AMD or CommonJS loaders.
$ npm install --save-dev gulp-jade-template-concat
var jade = require('gulp-jade');
var jadeConcat = require('gulp-jade-template-concat');
gulp.task("client-templates", function(){
gulp.src('src/jade/templates/**/*.jade')
.pipe(jade({
client: true
})
.pipe(jadeConcat('mytemplates.js', {templateVariable:"templates"}))
.pipe(gulp.dest('build/templates/'))
});
This compiles all of your client side jade templates into a file called mytemplates.js
. The templateVariable
option is optional and will default to templates
if it is not set.
Link the concatenated file with a script tag
script(src="templates/mytemplates.js")
Access the generated templates using dot or bracket access notation.
templates['template1'];
templates.template2;