0

我有一个 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) {});

比我得到一个模块超时。

我究竟做错了什么?

4

1 回答 1

1

当您映射Distribution到 时Distribution.Router,您正在创建一个循环依赖项,因为Distribution.Router还依赖于Distribution.

要解决此问题,只需添加另一行覆盖地图仅Distribution用于Distribution.Router

map: {
    "*": {
        "Distribution": "Distribution.Router"
    },
    "Distribution.Router": {
        "Distribution": "Distribution"
    }
}
于 2012-11-11T22:24:31.680 回答