Fix dynamic require for Webpack (#3306)

This commit is contained in:
BrennanConroy 2018-11-19 09:29:28 -08:00 committed by GitHub
parent e2a712a1cd
commit d0bcdf3dd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View File

@ -8,8 +8,10 @@ import { XhrHttpClient } from "./XhrHttpClient";
let nodeHttpClientModule: any;
if (typeof XMLHttpRequest === "undefined") {
// tslint:disable-next-line:no-var-requires
nodeHttpClientModule = require("./NodeHttpClient");
// In order to ignore the dynamic require in webpack builds we need to do this magic
// @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}. */

View File

@ -39,10 +39,11 @@ const MAX_REDIRECTS = 100;
let WebSocketModule: any = null;
let EventSourceModule: any = null;
if (typeof window === "undefined" && typeof require !== "undefined") {
// tslint:disable-next-line:no-var-requires
WebSocketModule = require("ws");
// tslint:disable-next-line:no-var-requires
EventSourceModule = require("eventsource");
// In order to ignore the dynamic require in webpack builds we need to do this magic
// @ts-ignore: TS doesn't know about these names
const requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
WebSocketModule = requireFunc("ws");
EventSourceModule = requireFunc("eventsource");
}
/** @private */