SignalR & require.js configuration

こ雲淡風輕ζ 提交于 2019-12-03 08:27:52

问题


I'm incorporating SignalR into a project where I'm already using require.js to handle my scripts dependencies.

I'm having a little trouble making sure "/signalr/hubs" is called after "jquery.signalR-1.1.2" loads.

I got it to work, but I'm wondering if there is a better alternative out there.

This is what I have:

require(["signalr"], function () {
  require(["noext!/signalr/hubs"], function () {
      //initialize and work with the hub here
  }
}

Is there a way I can create a shim here to establish the dependency between signalr/hubs and the signalr script?

Thanks!


回答1:


This works for me with SignalR 1.1.2:

require.config({
baseUrl: "/<your scripts dir>",
paths: {
    "jquery": "jquery-<your jquery version>.min",
    "signalr.core": "jquery.signalR-<your signalr version>.min",
    "signalr.hubs": "/signalr/hubs?"
},
shim: {
    "jquery": {
        exports: "$"
    },
    "signalr.core": {
        deps: ["jquery"],
        exports: "$.connection"
    },
    "signalr.hubs": {
        deps: ["signalr.core"],
    }
}
});

require(["jquery", "signalr.hubs"],
    function($)
    {
        var hubProxy = $.connection.myHub;

        // ... go to town ...
    });


来源:https://stackoverflow.com/questions/17598006/signalr-require-js-configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!