gulp-inject-template
v0.2.2
Published
Replaces require calls to html files with precompiled lodash/underscore template functions in your JS files
Downloads
9
Maintainers
Readme
gulp-inject-template
Replaces require
calls to html files with precompiled lodash/underscore template functions in your JS files.
Example
Input
var template = require('./template.html');
<!-- ./template.html -->
<h1>Template</h1>
With variable: <%= data %>
Output
var template = function(obj) {
obj || (obj = {});
var __t, __p = '';
with (obj) {
__p += '<h1>Template</h1>\nWith variable: ' +
((__t = ( data )) == null ? '' : __t);
}
return __p
};
Usage
gulp.task('build', function() {
return gulp.src('src/**/*.js', {buffer: false})
.pipe(injectTemplate(options))
.pipe(gulp.dest('./dist'));
});
Arguments
| Argument | Type | Description |
|---|---|---|
| options
| optional, Object | Object that will be passed down to lodash template function as options. More details in the lodash documentation. |
Using gulp-inject-template
with buffers
gulp-inject-template
currently does not support buffers.
If you want to use it with Babel or another module that does not support streams, you can wrap those plugins using gulp-streamify.
var streamify = require('gulp-streamify');
gulp.task('build', function() {
return gulp.src('src/**/*.js', {buffer: false})
.pipe(streamify(babel()))
.pipe(injectTemplate({variable: 'data'}))
.pipe(gulp.dest(dist))
;
});
Todo
- [ ] Support source maps
- [ ] Support buffers