【问题标题】:compile handlebars template with Brunch.io使用 Brunch.io 编译车把模板
【发布时间】: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


    【解决方案1】:

    发现问题。

    handlebars-brunch 插件和 static-handlebars-brunch 插件似乎不能一起使用。

    卸载 static-handlebars-brunch 后,我可以看到我的车把模板编译到我的 app.js 中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 2019-04-05
      • 1970-01-01
      相关资源
      最近更新 更多