This project is no longer being maintained. It's suggested that an alternative be used instead.
Compile static ( no logic ) HTML templates into javascript files
This plugin is heavily inspired by Emanuele Ingrosso's gulp plugin which was itself inspired by Sindre Sorhus's gulp-nunjucks plugin.
Install with npm
npm install gulp-html-compile --save-dev
<h1 class="my-header">Welcome to my awesome site!</h1>
var gulp = require( 'gulp' ),
template = require( 'gulp-html-compile' ),
concat = require( 'gulp-concat' ),
wrap = require( 'gulp-wrap' );
gulp.task( 'templates', function() {
gulp.src( './templates/**/*.html' )
.pipe( template({
name: function( file ) {
return file.relative.split( '.' )[ 0 ];
},
namespace: 'myTemplates'
}))
.pipe( concat( 'myTemplates.js' ))
.pipe( wrap( 'module.exports = window["myTemplates"]'))
.pipe( gulp.dest( './js/'));
});
Type: object
Type: string
Default: Relative template path
Example: templates/header.html
You can override the default behavior by supplying a function which gets the current File object and is expected to return the name.
{
name: function( file ) {
return file.relative.split( '.' )[ 0 ];
}
}
Type: 'string' Default: 'templates'
The namespace in which the precompiled templates will be assigned.
{
namespace: 'MyCoolTemplates'
}