Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please update the usage instructions with an example for "traditional" HTML without Babel/ES6 Modules #55

Open
daiplusplus opened this issue Nov 12, 2020 · 0 comments

Comments

@daiplusplus
Copy link

daiplusplus commented Nov 12, 2020

(I'd like to preface this post with a huge "thank you" for recently updating the library for SignalR 2.4.1 - that was only a few hours ago!)


In the old world, using the original SignalR client library is straightforward:

  1. Ensure you have jquery-2.2.4.min.js and jquery.signalr.2.4.1.js in your /scripts/ directory.

    • These files are automagically added to your project when you add the SignalR NuGet packages.
  2. Open your HTML file or template (e.g. Site.master, _Layout.cshtml, index.html, etc).

  3. Add this to your <head>:

    <script type="text/javascript" src="/scripts/jquery-2.2.4.min.js"></script>
    <script type="text/javascript" src="/scripts/jquery.signalr.2.4.1.js"></script>
    <script type="text/javascript" src="/signalr/hubs"></script>
    
  4. Add another <script> below that which then uses $.connection et cetera.


Now, I'm needing to use signalr-no-jquery in a project that doesn't have an existing JavaScript build process (beyond MSBuild/Visual Studio's built-in TypeScript compilation) and I'm stuck.

I was under the impression that signalr-no-jquery is a drop-in replacement for both jquery-2.2.4.min.js and jquery.signalr.2.4.1.js, but when I did npm install --save [email protected] I saw that the node_modules/signalr-no-jquery/build directory contained 2 files:

  • jQueryShim.js
  • signalR.js

and when I looked inside of those files, I saw they were both used require(), module.exports, and Object.defineProperty(exports, "__esModule" ), { etc } which means I can't use these files directly in a web-page (I think? please correct me if I'm wrong). And why is jQueryShim.js a separate file? I thought the whole point of signalr-no-jquery was that the jQuery shim is embedded within the signalr-no-jquery script file?

the documentation page says to just use import { hubConnection } from 'signalr-no-jquery, but I can't do that because:

  • My web-application needs to support browsers that don't support <script type="module">.
  • from 'signalr-no-jquery' won't work anyway because there is no file named signalr-no-jquery/index.js.
  • And as said above, require(), module, and exports can't be used in client-code.

So how do I actually use signalr-no-jquery with a traditional SSR web-application without a JavaScript build process?

I just want something like this:

    <script type="text/javascript" src="/scripts/signalr-no-jquery.min.js"></script>
    <script type="text/javascript" src="/signalr/hubs"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant