1

我尝试使用 Ember 2.0 并有下一个文件 config.js

System.config({
  "baseURL": "/static/js",
  "transpiler": "traceur",
  "paths": {
    "*": "*.js",
    "github:*": "jspm_packages/github/*.js"
  }
});

System.config({
  "map": {
    "ember": "github:components/ember@2.0.0",
    "traceur": "github:jmcriffey/bower-traceur@0.0.88",
    "traceur-runtime": "github:jmcriffey/bower-traceur-runtime@0.0.88",
    "github:components/ember@2.0.0": {
      "jquery": "github:components/jquery@2.1.4",
      "handlebars": "github:components/handlebars@1.3.0"
    }
  }
});

应用程序.js

import Ember from "ember";
let App = Ember.Application.create({
    LOG_TRANSITIONS: true,
    LOG_TRANSITIONS_INTERNAL: true,
});

和 index.html

<script src="{% static "js/jspm_packages/system.js" %}"></script>
<script src="{% static "js/config.js" %}"></script>
<script>
    System.import('app');
</script>

加载后我有下一个错误

Uncaught (in promise) Error: Cannot read property 'Ember' of undefined
    Error loading http://localhost:9090/static/js/app.js
    at http://localhost:9090/static/js/jspm_packages/github/components/ember@2.0.0/ember.js!transpiled:16:38
    at http://localhost:9090/static/js/jspm_packages/github/components/ember@2.0.0/ember.js!transpiled:97:11
    at execute (http://localhost:9090/static/js/jspm_packages/github/components/ember@2.0.0/ember.js!transpiled:25603:9)
    at m (http://localhost:9090/static/js/jspm_packages/system.js:4:20821)
    at m (http://localhost:9090/static/js/jspm_packages/system.js:4:20756)
    at m (http://localhost:9090/static/js/jspm_packages/system.js:4:20756)
    at Object.Promise.all.then.execute (http://localhost:9090/static/js/jspm_packages/system.js:4:23421)
    at b (http://localhost:9090/static/js/jspm_packages/system.js:4:7874)
    at S (http://localhost:9090/static/js/jspm_packages/system.js:4:8253)
    at p (http://localhost:9090/static/js/jspm_packages/system.js:4:6131)

如果没有 systemjs 和 jspm 的加载脚本总是有效。但想使用 jspm 和 systemjs :) 在我使用 ember 1.13 并且配置工作之前。我认为配置 jquery 有问题

4

1 回答 1

1

看起来 Ember 的包并不总是与 jspm 兼容。我总是在我的package.json

"jspm": {
  "overrides": {
      "github:components/ember@2.0.0": {
      "main": "ember.debug",
      "files": [
        "ember.prod.js",
        "ember.debug.js"
      ],
      "dependencies": {
        "jquery": "github:components/jquery@^2.1.3"
      },
      "shim": {
        "ember.prod": {
          "deps": [
            "jquery"
          ],
          "exports": "Ember"
        },
        "ember.debug": {
          "deps": [
            "jquery"
          ],
          "exports": "Ember"
        }
      }
    }
  }
}

它指示 jspm 仅安装 Ember 的 prod 和 debug 版本,并正确描述所有依赖项和导出。如果您使用它,则需要jspm install在将其添加到 package.json 后再次运行。

您可能会遇到 htmlbars 模板的另一个问题。我有一个插件可以解决这个问题:https ://github.com/n-fuse/plugin-ember-hbs :

jspm install hbs=github:n-fuse/plugin-ember-hbs@2.0.0

应该允许导入 hbs 模板而无需在依赖项中添加编译器。

另请参阅我创建的入门项目:https ://github.com/OrKoN/jspm-ember-playground

于 2015-08-14T09:13:25.540 回答