【发布时间】:2016-09-07 20:22:38
【问题描述】:
我正在使用 brunch.io 和 Handlebars plugin。 为了编译我的模板,我需要获取模板,据我所知,我应该能够使用 require() 来完成
所以这样的事情应该可以工作:
var tmp = require('./templates/projects');
var template = Handlebars.compile(tmp);
var compiledHtml = template(data); //data is a var with data for the template inside
viewEl.innerHTML = template; //viewEl is id of div where i want to show the tmpl
但如果我这样做了,我在构建时不会出错,而是在我在浏览器中检查时得到它:
initialize.js:52 Uncaught Error: Cannot find module 'templates/projects' from 'initialize.js'
initialize.js 是我的主要源 js 文件。
据我了解,它不起作用,因为我的模板没有按照我的配置文件编译到 public/javascript/app.js 下的公共文件夹中:
module.exports = {
// See http://brunch.io for documentation.
files: {
javascripts: {
joinTo: {
'js/app.js': /^app/
}
},
stylesheets: {joinTo: 'css/main.css'},
templates: { joinTo: 'js/app.js'}
}
}
或者我真的错过了什么?
【问题讨论】:
标签: javascript handlebars.js brunch