Nonlinear Programming Methods

    gulp-tpl2amd

    1.0.1 • Public • Published

    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

    Install

    npm i gulp-tpl2amd

    DownloadsWeekly Downloads

    2

    Version

    1.0.1

    License

    none

    Last publish

    Collaborators

    • dexteryy