在CoffeeScript中,我有以下(非常简单的)模块定义:
# backbone/routers/appointments_router.js.coffee
define ["app", "underscore", "backbone"], (App, _, Backbone) ->
console.log(Backbone)这是我的配置文件
# application.js.coffee
requirejs.config
paths:
underscore: "lodash.min"
backbone: "backbone"
appointmentsRouter: "backbone/routers/appointments_router"
"backbone-relational": "backbone-relational"
requirejs ["app", "underscore", "backbone", "appointmentsRouter"], (App, _, Backbone, AppointmentsRouter) ->下面是所发生的事情:当我加载页面时,我会在控制台中获得undefined,即使主干被列为依赖项。更令人费解的是,如果我在控制台中输入Backbone,就会定义主干。
appointments_router.js.coffee 怎么可能最终会被评估,但是我的不知道骨干吗?
发布于 2012-08-14 13:51:04
下划线或主干不是AMD兼容,所以定义路径是不够的。幸运的是,Require.js提供了 -functionality作为这个问题的答案。
所以你得加上这样的东西
requirejs.config( // shouldn't this be just require?
paths: ..., // don't change these
shim: {
"underscore": {
exports: "_" // define the export
},
"backbone": {
deps: ["underscore"], // define dependencies for backbone
exports: "Backbone"
}
}
);希望这能帮上忙!
https://stackoverflow.com/questions/11953585
复制相似问题