Skip to content

dexteryy/gulp-tpl2amd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Convert js templates to AMD modules no matter what syntax

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published