从所有信号器 js 文件生成一个 js 文件

Generate one js file from all signalr js files

我最初采用了本教程中的以下代码:SignalR Getting Started Application 将创建一个聊天室。我稍微清理了 html 代码,只得到我需要的部分。我验证聊天仍然有效:

<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.6.4.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/signalr/jquery.signalR-2.0.0.js"></script>
<script src="/signalr/hubs"></script>

<script type="text/javascript">
$(function () {
    var chat = $.connection.chatHub;

    chat.client.broadcastMessage = function (name, message) {
        console.log('name is: ' + name);
        console.log('message is: ' + message);
    };
    $.connection.hub.start().done(function () {
        chat.server.send("khaled7", "message9");
    });
});
</script>

如您所见,有 3 个 javascript 文件和 1 个脚本块:

现在,我需要将所有这些脚本合并到一个文件中并将其发送到我的远程移动客户端。我还在 web 端,所以我开始加入 files/script 自上而下。加入前 2 名工作正常,但一旦尝试添加第三名 (/signalr/hubs),我在 chrome 控制台中收到 404 错误:

http://localhost:52528/HubSample/signalr/negotiate?connectionData=%5B%7B%22name%22%3A%22chathub%22%7D%5D&clientProtocol=1.3&_=1464332439400

我必须加入他们。我该如何解决这个错误!?

"/signalr/hubs" 不是物理文件,它是 dynamically generated JavaScript code.

SignalR creates the JavaScript code for the proxy on the fly and serves it to the client in response to the "/signalr/hubs" URL.

您想要做的是创建一个 physical file for the SignalR generated proxy,您可以将其添加到您的单个文件中:

  1. Install the Microsoft.AspNet.SignalR.Utils NuGet package.
  2. Open a command prompt and browse to the tools folder that contains the SignalR.exe file. The tools folder is at the following location:
    [your solution folder]\packages\Microsoft.AspNet.SignalR.Utils.2.1.0\tools

  3. Enter the following command:
    signalr ghp /path:[path to the .dll that contains your Hub class]
    The path to your .dll is typically the bin folder in your project folder.

  4. This command creates a file named server.js in the same folder as signalr.exe.

  5. Put the server.js file in an appropriate folder in your project, rename it as appropriate for your application, and add a reference to it in place of the "signalr/hubs" reference.

问题是您必须为集线器中的每个更改执行此操作。每一个。单身的。时间.