Swig precompiler for gulp
Install as a development dependency using npm
npm install --save-dev gulp-swig-precompile
This example makes your templates AMD modules.
var gulp = require('gulp'),
swig = require('gulp-swig-precompile'),
path = require('path');
gulp.task('templates', function () {
gulp.src('views/**/*.html', { base: path.join(__dirname, 'views') })
.pipe(swig({ output: 'define(function () { return <%= template %>; });' }))
.pipe(gulp.dest('public/js'));
});
Note that setting the base path also sets the root directory for the templates, which is useful for templates that make use of the extends, import, and include tags.
You can pass in the same options as those avialble in Swig Options, as well as the desired output format, custom filters, and custom tags.
Default: var tpl = <%= template %>;
An inline template specifying how you would like the results of the precompilation formatted. Two variables are passed in to the template: template and file.
Example usage:
{ output: 'exports["<%= file.relative %>"]=<%= template %>;' }
An object containing custom filters, where the keys are filter names, and values are corresponding filter functions.
To learn more on custom filters in Swig, read the official documentation regarding this.
An object containing custom tags, where the keys are tag names, and values are corresponding tag objects with parse, compile, ends, and blockLevel properties.
To learn more on custom tags in Swig, read the official documentation regarding this.
