gulp-tmpl2js

0.1.1 • Public • Published

gulp-tmpl2js

NPM version Build Status Downloads Dependencies

Gulp plugin for compile tmpl to js string, optional amd or commonjs wrapper.

Install

$ npm install --save-dev gulp-tmpl2js

Usage

var gulp = require('gulp');
var tmpl2js = require('gulp-tmpl2js');
 
gulp.task('tmpl2js', function () {
    return gulp.src('src/*.tpl')
        .pipe(tmpl2js())
        .pipe(gulp.dest('dist'));
});

API

tmpl2js([options])

Options:

  • mode: A string naming js code style. Optional. Possible values:

    • undefined (default): keep space and carriage of source html
    • compress: strip the extra spaces or carriage at the beginnings and ends of the lines
    • format: format js code as spec
  • wrap: A string naming js code wrapper. Optional. Possible values:

    • undefined (default): no wrapper
    • amd: wrap with AMD
    • commonjs: wrap with CommonJS
  • ignoreScriptTag: boolean to ignore fix split the script tag when writing it with document write. Defaults to false

  • clone: boolean to keep source tpl file. Defaults to false

  • ext: target file extname. Defaults to .js

Examples

Compress html and wrap with define

var gulp = require('gulp');
var tmpl2js = require('gulp-tmpl2js');
 
gulp.task('tmpl2js', function () {
    return gulp.src('src/*.tpl')
        .pipe(tmpl2js({
            mode: 'compress',
            wrap: 'amd'
        }))
        .pipe(gulp.dest('dist'));
});

Input

<div id="i-am-a-id">
  <div class="i-am-a-class">
    i am test
  </div>
</div>
<script>
    var test = 'test';
    alert(test);
</script> 

Output

define(function () {return '<div id="i-am-a-id"><div class="i-am-a-class">i am test</div></div><script>var test = \'test\';alert(test);</'+'script>';});

Related

License

MIT

Package Sidebar

Install

npm i gulp-tmpl2js

Weekly Downloads

1

Version

0.1.1

License

MIT

Last publish

Collaborators

  • junmer