简体   繁体   English

使用Brunch.io编译车把模板

[英]compile handlebars template with Brunch.io

I'm using brunch.io together with Handlebars plugin . 我正在将brunch.io和Handlebars插件一起使用。 In order to compile my template, i need to get the template and for what i understood i should be able to do it with require() 为了编译我的模板,我需要获取模板,对于我的理解,我应该能够使用require()来做到这一点。

So something like this should work: 所以这样的事情应该工作:

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

But if i do so, i don't get error while building, instead i get it when i check in the browser: 但是,如果这样做,在构建时不会出现错误,而是在我在浏览器中签入时得到了它:

initialize.js:52 Uncaught Error: Cannot find module 'templates/projects' from 'initialize.js'

where initialize.js is the my main source js file. 其中initialize.js是我的主要源js文件。

for my understanding, it doesn't work because my template isn't compiled in my public folder under public/javascript/app.js as per my config file: 以我的理解,它不起作用,因为我的模板未按照配置文件在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'}
  }
}

Or am I really missing something here? 还是我真的在这里缺少什么?

Found the problem. 找到了问题。

Looks like that handlebars-brunch plugin and static-handlebars-brunch plugin don't work together. 看起来handlebars-brunch插件和static-handlebars-brunch插件不能一起使用。

Once i uninstall static-handlebars-brunch, i can see my handlebars template compiled into my app.js 卸载static-handlebars-brunch后,我可以看到我的车把模板已编译到我的app.js中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM