I always get a message saying:
$.hubConnection is not a function
Error: jQuery was not found. Please ensure jQuery is referenced before the SignalR client JavaScript file. consoling out "$" and "jquery" is undefined.
What do I need to do, to get signalr working using webpack?
Thanks to hannes and this guide from Microsoft I managed to get SignalR working with Webpack and TypeScript using the ES6 syntax.
Before:
After:
webpack.config.js:
packages.json:
NB: You will also need to remove loading of
<script src="/signalR/hubs"/>
as it's no longer needed.Clean solution: use expose-loader !!
inside your vendor.ts
inside your webpack.config.ts
Explanation: The jquery.signalR.js script is indeed not written as a umd module. Which makes it by default, not to be loadable by webpack. It doesn't require jquery, but assumes that Jquery lives on the global variable window.jQuery. We can make this work in webpack by importing the jquery module with the expose-loader. This loader will make sure that the exported value of jquery, is exposed to the jQuery global var. Thus allowing to load the signalr.js script as the next module.
Also if you want to later use signalr by using $, you also will have to use the provideplugin for the jquery module. inside webpack.config.js