SignalR & require.js configuration

前端 未结 1 1359
日久生厌
日久生厌 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: "/",
    paths: {
        "jquery": "jquery-.min",
        "signalr.core": "jquery.signalR-.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)
提交回复
热议问题