SignalR & require.js configuration

前端 未结 1 1357
日久生厌
日久生厌 2021-02-03 11:09

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

I\'m having a little

相关标签:
1条回答
  • 2021-02-03 11:51

    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 ...
        });
    
    0 讨论(0)
提交回复
热议问题