UNPKG

ali-tmodjs

Version:
25 lines (24 loc) 685 B
var stringify = function (code) { return "'" + code .replace(/('|\\)/g, '\\$1') .replace(/\r/g, '\\r') .replace(/\n/g, '\\n') + "'"; }; /** * 自定义模板编译 * @param {[type]} id 输出的模块id * @param {[type]} source 模板源码 * @param {[type]} options 编译配置项 * @return {[type]} [description] */ module.exports = function(id,source,options){ var dep = source.match(/<!--#\((.*)\)-->/); if(dep[1]){ dep = dep[1]; } return "define('"+id+"',['"+dep+"']," + "function(){" + "return "+stringify(source)+";" + "});"; }