Fix dynamic require for Webpack (#3306)
This commit is contained in:
parent
e2a712a1cd
commit
d0bcdf3dd9
|
|
@ -8,8 +8,10 @@ import { XhrHttpClient } from "./XhrHttpClient";
|
||||||
|
|
||||||
let nodeHttpClientModule: any;
|
let nodeHttpClientModule: any;
|
||||||
if (typeof XMLHttpRequest === "undefined") {
|
if (typeof XMLHttpRequest === "undefined") {
|
||||||
// tslint:disable-next-line:no-var-requires
|
// In order to ignore the dynamic require in webpack builds we need to do this magic
|
||||||
nodeHttpClientModule = require("./NodeHttpClient");
|
// @ts-ignore: TS doesn't know about these names
|
||||||
|
const requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
|
||||||
|
nodeHttpClientModule = requireFunc("./NodeHttpClient");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Default implementation of {@link @aspnet/signalr.HttpClient}. */
|
/** Default implementation of {@link @aspnet/signalr.HttpClient}. */
|
||||||
|
|
|
||||||
|
|
@ -39,10 +39,11 @@ const MAX_REDIRECTS = 100;
|
||||||
let WebSocketModule: any = null;
|
let WebSocketModule: any = null;
|
||||||
let EventSourceModule: any = null;
|
let EventSourceModule: any = null;
|
||||||
if (typeof window === "undefined" && typeof require !== "undefined") {
|
if (typeof window === "undefined" && typeof require !== "undefined") {
|
||||||
// tslint:disable-next-line:no-var-requires
|
// In order to ignore the dynamic require in webpack builds we need to do this magic
|
||||||
WebSocketModule = require("ws");
|
// @ts-ignore: TS doesn't know about these names
|
||||||
// tslint:disable-next-line:no-var-requires
|
const requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
|
||||||
EventSourceModule = require("eventsource");
|
WebSocketModule = requireFunc("ws");
|
||||||
|
EventSourceModule = requireFunc("eventsource");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @private */
|
/** @private */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue