我有一个Mediator-Sandbox库和一个建立在这个库之上的路由器扩展。
图书馆是这样构建的:
(function(window) {
var MedSan = {};
window.MedSan = MedSan;
})(this);
扩展名如下:
(function(_, Backbone, MedSan) {
MedSan.Router = {};
})(_, Backbone, MedSan);
要求加载扩展程序的配置如下所示:
require.config({
baseUrl: "javascripts",
shim: {
"jquery": {
exports: "$"
},
"underscore": {
exports: "_"
},
"backbone": {
deps: ['jquery', 'underscore'],
exports: "Backbone"
},
"Distribution": {
exports: "Distribution"
},
"Distribution.Router": {
deps: ['underscore', 'backbone', 'Distribution'],
exports: "Distribution"
}
},
/*
map: {
"*": {
"Distribution": "Distribution.Router"
}
},
*/
paths: {
"jquery": "Vendors/jquery",
"underscore": "Vendors/underscore",
"backbone": "Vendors/backbone",
"Distribution": "Distribution/Distribution",
"Distribution.Router": "Distribution/Plugins/Router"
}
});
我现在可以使用我的完整库:
require(['Distribution.Router'], function(Distribution) {});
当我取消注释地图配置时,我可以通过这种方式使用带有路由器扩展的完整加载模块:
require(['Distribution'], function(Distribution) {});
比我得到模块超时。
我做错了什么?
答案 0 :(得分:1)
当您将Distribution
映射到Distribution.Router
时,您正在创建循环依赖关系,因为Distribution.Router
还取决于Distribution
。
要解决此问题,只需在Distribution
中添加覆盖Distribution.Router
地图的另一行:
map: {
"*": {
"Distribution": "Distribution.Router"
},
"Distribution.Router": {
"Distribution": "Distribution"
}
}