1.1.1 • Published 6 years ago

gulp-pug-template-concat v1.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

gulp-pug-template-concat

Compiles Pug templates single file containing template functions. Supports commonJS.

Based on gulp-jade-templates-concat by Nicholas Stonehouse.

Install

$ npm install --save-dev gulp-pug-template-concat

Usage

Gulpfile

var pug = require('gulp-pug');
var pugConcat = require('gulp-pug-template-concat');

gulp.task("client-templates", function(){
    gulp.src('src/pug/templates/**/*.pug')
        .pipe(pug({
            client: true
        })
        .pipe(pugConcat('mytemplates.js', {
            // uncomment to change templateVariable name. "templates" by default
            // templateVariable: "templates"
            
            // uncomment following line to export templates in commonJS manner
            // commonJS: true        
        }))
        .pipe(gulp.dest('build/templates/'))
});

This compiles all of your client side pug templates into a file called mytemplates.js. The templateVariable option is optional and will default to templates if it is not set.

HTML/Pug

Link the concatenated file with a script tag

script(src="templates/mytemplates.js")

Javascript

Access the generated templates using dot or bracket access notation.

  templates['template1'];
  templates.template2;