A gulp plugin to compile [JST][] HTML templates to JavaScript functions using [lodash][].
In templates/test.html
:
<p>Hello {{place}}</p>
In your gulpfile:
var compiler = require('gulp-lodash-compile');
gulp.task('templates', function() {
gulp.src('templates/**/*.html')
.pipe(compiler('templates.js'));
.pipe(gulp.dest('js/'));
});
In your code:
var templates = require('js/templates.js');
var html = templates.test({
place: 'world';
})
console.log(html); // <p>Hello world</p>
This will compile the templates into a JavaScript AMD module.
- file
string
- The name of the file to use for the compiled templates
- options
object
- Options passed to the hogan task
The line delimiter, defaults to your operating system's newline.
Either amd
, commonjs
or false
for no wrapper, defaults to amd
. If wrapper is false
a local var templates
will be defined containing the templates.
Coming soon
A function that will be passed the file and should return a name for the template. By default uses the basename of the file without an extension.