1.0.1 • Published 10 years ago

gulp-tpl2amd v1.0.1

Weekly downloads
1
License
-
Repository
github
Last release
10 years ago

gulp-tpl2amd

Convert js templates to AMD modules no matter what syntax

Install

$ npm install --save-dev gulp-tpl2amd

Usage

▸ 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"}; 
});

License

MIT © dexteryy