gulp-tmpl2js
v0.1.1
Published
Gulp plugin for compile tmpl to js string, optional amd or commonjs wrapper.
Downloads
4
Maintainers
Readme
gulp-tmpl2js
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 htmlcompress
: strip the extra spaces or carriage at the beginnings and ends of the linesformat
: format js code as spec
wrap
: A string naming js code wrapper. Optional. Possible values:ignoreScriptTag
: boolean to ignore fix split the script tag when writing it with document write. Defaults tofalse
clone
: boolean to keep source tpl file. Defaults tofalse
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