如何在Browserify中使用html模板 [英] How can I require a html template with Browserify
本文介绍了如何在Browserify中使用html模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试找出一种简单的方法,在脚本中需要一个html模板,然后从CLI运行browserify。
I'm trying to figure out an easy way to require a html template in the script and then run browserify from the CLI.
说我想抓一个模板并将其附加到正文。
Say I want to grab a template and append it to the body.
//index.js
var template = require('./template.html');
document.body.appendChild(template);
和
<!-- template.html -->
<p>Woooo!</p>
然后使用CLI将其全部包装在Browserify中。
Then using the CLI to wrap it all up in Browserify.
browserify index.js> build.js
在浏览器中加载index.html模板时引用 build.js
我在控制台中收到此错误:
When loading an index.html template in the browser that references build.js
I get this error in the console:
Uncaught SyntaxError: Unexpected token <
引用
....
},{}],3:[function(require,module,exports){
<div class="slide">
<h2 data-slide-title></h2>
<div data-slide-copy></div>
</div>
},{}]},{},[1])
推荐答案
使用: https://github.com/substack/brfs
1
npm install brfs
2
var fs = require('fs');
var html = fs.readFileSync(__dirname + '/robot.html', 'utf8');
console.log(html);
3
browserify -t brfs example/main.js > bundle.js
这篇关于如何在Browserify中使用html模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文