Skip to content

Commit f00fcb3

Browse files
frankwintershellscape
authored andcommitted
Allow --open option to specify the browser to use (#825)
* Add optionally browser parameter to --open * Fix code style issues * Fix last code style issue * Replace array spread * Fix whitespace issue * Add .idea to gitignore and remove files * Fix whitespaces * Ignore and remove package-lock.json * refactor argument composition * removing trailing spaces * improve open option description to match pr
1 parent cf5dda8 commit f00fcb3

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ node_modules
55
/client/sockjs.bundle.js
66
/coverage
77
*.pem
8+
.idea/
9+
/package-lock.json

bin/webpack-dev-server.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ yargs.options({
100100
describe: 'close when stdin ends'
101101
},
102102
open: {
103-
type: 'boolean',
104-
describe: 'Open default browser'
103+
type: 'string',
104+
describe: 'Open the default browser, or optionally specify a browser name'
105105
},
106106
useLocalIp: {
107107
type: 'boolean',
@@ -324,11 +324,15 @@ function processOptions(webpackOptions) {
324324

325325
if (argv['disable-host-check']) { options.disableHostCheck = true; }
326326

327-
if (argv.open || argv['open-page']) {
327+
if (argv['open-page']) {
328328
options.open = true;
329329
options.openPage = argv['open-page'];
330330
}
331331

332+
if (typeof argv.open !== 'undefined') {
333+
options.open = argv.open !== '' ? argv.open : true;
334+
}
335+
332336
if (options.open && !options.openPage) { options.openPage = ''; }
333337

334338
if (argv.useLocalIp) { options.useLocalIp = true; }
@@ -452,9 +456,18 @@ function reportReadiness(uri, options) {
452456

453457
if (options.bonjour) { console.log('Broadcasting "http" with subtype of "webpack" via ZeroConf DNS (Bonjour)'); }
454458
}
459+
455460
if (options.open) {
456-
open(uri + options.openPage).catch(() => {
457-
console.log('Unable to open browser. If you are running in a headless environment, please do not use the open flag.');
461+
let openOptions = {};
462+
let openMessage = 'Unable to open browser';
463+
464+
if (typeof options.open === 'string') {
465+
openOptions = { app: options.open };
466+
openMessage += `: ${options.open}`;
467+
}
468+
469+
open(uri + (options.openPage || ''), openOptions).catch(() => {
470+
console.log(`${openMessage}. If you are running in a headless environment, please do not use the open flag.`);
458471
});
459472
}
460473
}

lib/optionsSchema.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,15 @@
200200
"type": "boolean"
201201
},
202202
"open": {
203-
"description": "Let the CLI open your browser.",
204-
"type": "boolean"
203+
"description": "Let the CLI open your browser with the URL.",
204+
"anyOf": [
205+
{
206+
"type": "string"
207+
},
208+
{
209+
"type": "boolean"
210+
}
211+
]
205212
},
206213
"useLocalIp": {
207214
"description": "Let the browser open with your local IP.",

0 commit comments

Comments
 (0)