Coder Social home page Coder Social logo

gulp-html2js's Introduction

gulp-tpl2js

将模板文件转成js代码或js模块

用法

tpl2js({opt})

##例子

var gulp = require('gulp');
var tpl2js = require('gulp-tpl2js');
gulp.task('trans', function() {
  gulp.src('./tpl/**')
  	.pipe(tpl2js())
  	.pipe(gulp.dest('./output/tpl'))
});

参数

opt(选填): {
	type : 'amd' //是否转成amd/cmd模板,默认js字符串
	modBase: 'tpl' //模块id基础路径, 默认tpl
}

自定义js字符串的变量名

<!--varname:offerlist-->
<div>varname为输出js字符串的变量名</div>
//tpl2js()
//输出filename.js
offerlist = '<div>varname为输出js字符串的变量名</div>'

转成amd模块示例

<!--varname:offerlist-->
<div>varname为输出js字符串的变量名</div>
//tpl2js({type:'amd',modBase:'view'})
//输出filename.js
(function() {
  var tpl = '<!--varname:offerlist-->\
<div>varname为输出js字符串的变量名</div>'
  ;

  // cmd
  if (typeof module !== "undefined" && module.exports) {
      module.exports = tpl;
  }
  // amd
 if (typeof define === "function" && (define.amd||define.fmd)) {
      define("view/filename", [], function () {
          return tpl;
      });
  }
})();

gulp-html2js's People

Contributors

chunterg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.