Skip to content

Commit

Permalink
fix: remove explicit 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

Backported from master: 82cdca2
  • Loading branch information
darrachequesne committed Jun 4, 2020
1 parent e488120 commit 85e544a
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/server.js
Expand Up @@ -102,12 +102,8 @@ Server.prototype.init = function () {

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

var wsModule;
switch (this.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
var wsModule = this.wsEngine === 'ws' ? require('ws') : require(this.wsEngine);
this.ws = new wsModule.Server({
noServer: true,
clientTracking: false,
Expand Down

1 comment on commit 85e544a

@p3nGu1nZz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. thank you.

Please sign in to comment.