html2js
RT. html2js. 解决require tpl无法跨域的问题
简单使用示例:
test.html:
<div id="i-am-a-id">
<div class="i-am-a-class">
i am test
</div>
</div>
js:
var fs = require('fs');
var html2js = require('../html2js');
var filename = 'test.html';
var html = fs.readFileSync(filename, 'utf8');
var modes = ['format', 'default', 'compress'];
var output = modes.map(
function (mode) {
return ''
+ '// '
+ mode
+ '\n'
+ html2js(html, {
mode: mode,
wrap: true
});
}
).join('\n');
console.log(output);
fs.writeFile( filename + '.js', output );
output:
define(function () {
return ''
+ '<div id="i-am-a-id">'
+ '<div class="i-am-a-class">'
+ 'i am test'
+ '</div>'
+ '</div>';
});
define(function () {return '<div id="i-am-a-id">\n <div class="i-am-a-class">\n i am test\n </div>\n</div>';});
define(function () {return '<div id="i-am-a-id"><div class="i-am-a-class">i am test</div></div>';});