Skip to content

Commit

Permalink
fix: remove implicit require of uws
Browse files Browse the repository at this point in the history
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
  • Loading branch information
darrachequesne committed Jun 4, 2020
1 parent 94623c8 commit 82cdca2
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,9 @@ class Server extends EventEmitter {

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

let wsModule;
switch (this.opts.wsEngine) {
case "uws":
wsModule = require("uws");
break;
case "ws":
wsModule = require("ws");
break;
default:
throw new Error("unknown wsEngine");
}
// add explicit require for bundlers like webpack
const wsModule =
this.opts.wsEngine === "ws" ? require("ws") : require(this.opts.wsEngine);
this.ws = new wsModule.Server({
noServer: true,
clientTracking: false,
Expand Down

0 comments on commit 82cdca2

Please sign in to comment.