1

我正在使用grunt-ember-templates预编译 Handlebars 模板。脚本按以下顺序排列:

<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.3.0/handlebars.runtime.min.js"></script>
<script src="/js/ember.min.js"></script>
<script src="/js/app.js"></script>
<script src="/build/templates.js"></script>
<script src="/js/router.js"></script>
.....

templates.js

define(["ember"], function(Ember){

Ember.TEMPLATES["index"] = Ember.Handlebars.template(functionanonymous(Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [4,'>= 1.0.0'];
helpers = this.merge(helpers, Ember.Handlebars.helpers);
data = data || {};
var buffer = '', stack1, escapeExpression=this.escapeExpression, self=this;

function program1(depth0,data) {

var buffer = '';
...
.....
return buffer;

});

现在我得到这个Uncaught ReferenceError: define is not defined 错误,它指的是define(["ember"], function(Ember){. 我究竟做错了什么?

4

1 回答 1

1

在您的配置中设置amd为 false:

emberTemplates: {
  compile: {
    options: {
      amd: false,
      templateBasePath: /path\/to\//
    },
    files: {
      "path/to/result.js": "path/to/source.handlebars",
      "path/to/another.js": ["path/to/sources/*.handlebars", "path/to/more/*.handlebars"]
    }
  }
}

https://github.com/dgeb/grunt-ember-templates

于 2014-11-08T07:10:42.583 回答