gulp-micro-tpl-compiler

0.0.7 • Public • Published

gulp micro template编译器,将micro template提前预编译为function,提升模板性能。编译后的模板可通过配置支持seajs,requirejs,kissy,nodejs模块化,也可以完全自定义配置项wrap配置编译后代码的前后包裹。

特性

  • micro template直接使用js语法,近乎零学习成本
  • 通过编译micro template提升模板运行性能
  • 支持模板间互相调用
  • 因为使用js语法,支持同时运行在client(浏览器)端和server(nodejs)端
  • 支持模板编译报错提示错误信息,源模板行号
  • 支持模板运行错误时提示错误信息,源模板行号

使用

安装

npm install gulp-micro-tpl-compiler --save-dev

gulpfile.js

require('gulp-micro-tpl-compiler');

样例

gulp.task('compiler', function() {
    gulp.src('./src/**/*.mtpl.html')
        .pipe(plumber())
        .pipe(mtpl(
            {
                wrap: 'kissy'
            }
        ))
        .pipe(rename(function(path) {
            console.log(path.basename);
            path.extname = '.js';
        }))
        .pipe(gulp.dest('./build'))
});

参数说明

banner

类型: String

默认: ''

文件头。

lineNumber

类型: Boolean

默认: false

运行错误时是否提示行号,默认不提示。

wrap

类型: String|Object|function

可选: 'nodejs', 'requirejs', 'seajs', 'kissy', wormhole, 'default', {before: '', after: ''} or

function(code) {
    //do something
    return code;
}

Default: default

/**
 * options.wrap {Object}
 */
wrap {
    before: 'KISSY.add(function (S, require, exports, module) {\n module.exports = ',
    after: '});'
}

对代码进行封装,可以使用现有模板 'requirejs', 'nodejs', 'kissy'等等

鸣谢

grunt-micro-tpl-compiler项目。

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.7
    1
    • latest

Version History

Package Sidebar

Install

npm i gulp-micro-tpl-compiler

Weekly Downloads

1

Version

0.0.7

License

ISC

Last publish

Collaborators

  • codersheng