Skip to content

Commit 82cdca2

Browse files
fix: remove implicit require of uws
So that bundlers like webpack do not try to include it in the build. As a side-effect, any implementation which matches the API of the ws module can now be used. Before that change, you had to explicitly exclude uws: ``` // webpack.config.js module.exports = { // ... externals: { uws: 'uws' } }; ``` Related: #575
1 parent 94623c8 commit 82cdca2

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

lib/server.js

+3-11
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,9 @@ class Server extends EventEmitter {
6969

7070
if (this.ws) this.ws.close();
7171

72-
let wsModule;
73-
switch (this.opts.wsEngine) {
74-
case "uws":
75-
wsModule = require("uws");
76-
break;
77-
case "ws":
78-
wsModule = require("ws");
79-
break;
80-
default:
81-
throw new Error("unknown wsEngine");
82-
}
72+
// add explicit require for bundlers like webpack
73+
const wsModule =
74+
this.opts.wsEngine === "ws" ? require("ws") : require(this.opts.wsEngine);
8375
this.ws = new wsModule.Server({
8476
noServer: true,
8577
clientTracking: false,

0 commit comments

Comments
 (0)