Skip to content

Commit

Permalink
feat(hmr-ws-port): adds ability to explicitly set hmr ws port (#450)
Browse files Browse the repository at this point in the history
* feat(hmr-ws-port): adds ability to explicitly set hmr ws port

* fix(conflict): fix merge conflict

* fix(hmr-ws-port): change args, misc cleanup

* fix(hmr-ws-port): add args to cli
  • Loading branch information
ksafranski authored and devongovett committed Jan 1, 2018
1 parent b691513 commit 065a49e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/Bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class Bundler extends EventEmitter {
typeof options.minify === 'boolean' ? options.minify : isProduction,
hmr: typeof options.hmr === 'boolean' ? options.hmr : watch,
logLevel: typeof options.logLevel === 'number' ? options.logLevel : 3,
mainFile: this.mainFile
mainFile: this.mainFile,
hmrPort: options.hmrPort || 0
};
}

Expand Down Expand Up @@ -191,7 +192,7 @@ class Bundler extends EventEmitter {

if (this.options.hmr) {
this.hmr = new HMRServer();
this.options.hmrPort = await this.hmr.start();
this.options.hmrPort = await this.hmr.start(this.options.hmrPort);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/HMRServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ const WebSocket = require('ws');
const prettyError = require('./utils/prettyError');

class HMRServer {
async start() {
async start(port) {
await new Promise(resolve => {
this.wss = new WebSocket.Server({port: 0}, resolve);
this.wss = new WebSocket.Server({port}, resolve);
});

this.wss.on('connection', ws => {
Expand Down
5 changes: 5 additions & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ program
'set the port to serve on. defaults to 1234',
parseInt
)
.option(
'-h, --hmr-port <port>',
'set the port to serve HMR websockets, defaults to random',
parseInt
)
.option('--https', 'serves files over HTTPS')
.option('-o, --open', 'automatically open in default browser')
.option(
Expand Down

0 comments on commit 065a49e

Please sign in to comment.