Convert js templates to AMD modules no matter what syntax
$ npm install --save-dev gulp-tpl2amd
▸ bower_components/
▾ js/
▸ myapp/
▾ tpl/ # generated by gulp-tpl2amd
header.js
app.js
▸ vendor/
main.js
▸ scss/
▾ tpl/
▾ myapp/
header.tpl
gulpfile.js
gulpfile.js
var gulp = require('gulp');
var tpl2amd = require('gulp-tpl2amd');
gulp.task('build:tpl', ['clean:tpl'], function() {
gulp.src('tpl/myapp/**/*.tpl')
.pipe(tpl2amd())
.pipe(gulp.dest('js/myapp/tpl'));
});
js/myapp/app.js
define(['tpl/header'], function(tpl_header){
console.log(tpl_header.template);
});
tpl/myapp/header.tpl
<div class="header">
<h1>{%= title %}</h1>
</div>
js/myapp/tpl/header.js
define([], function(){
return {"template":"\n<div class=\"header\">\n <h1>{%= title %}</h1>\n</div>\n"};
});
MIT © dexteryy