From 065a49e8f673922e514c5279d79df74f052a1558 Mon Sep 17 00:00:00 2001 From: Kent Safranski Date: Mon, 1 Jan 2018 12:24:47 -0600 Subject: [PATCH] feat(hmr-ws-port): adds ability to explicitly set hmr ws port (#450) * 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 --- src/Bundler.js | 5 +++-- src/HMRServer.js | 4 ++-- src/cli.js | 5 +++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Bundler.js b/src/Bundler.js index de60f3d1f97..08ee747ee88 100644 --- a/src/Bundler.js +++ b/src/Bundler.js @@ -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 }; } @@ -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); } } diff --git a/src/HMRServer.js b/src/HMRServer.js index 8ce9b79832d..620d34eabd5 100644 --- a/src/HMRServer.js +++ b/src/HMRServer.js @@ -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 => { diff --git a/src/cli.js b/src/cli.js index add30aa5ea3..9dc5f71198f 100755 --- a/src/cli.js +++ b/src/cli.js @@ -13,6 +13,11 @@ program 'set the port to serve on. defaults to 1234', parseInt ) + .option( + '-h, --hmr-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(