diff --git a/.gitignore b/.gitignore index e4503a17c8..b54e4d88a2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ node_modules /client/sockjs.bundle.js /coverage *.pem +.idea/ +/package-lock.json diff --git a/bin/webpack-dev-server.js b/bin/webpack-dev-server.js index d5cfe9d0fa..6a607bff53 100755 --- a/bin/webpack-dev-server.js +++ b/bin/webpack-dev-server.js @@ -100,8 +100,8 @@ yargs.options({ describe: 'close when stdin ends' }, open: { - type: 'boolean', - describe: 'Open default browser' + type: 'string', + describe: 'Open the default browser, or optionally specify a browser name' }, useLocalIp: { type: 'boolean', @@ -324,11 +324,15 @@ function processOptions(webpackOptions) { if (argv['disable-host-check']) { options.disableHostCheck = true; } - if (argv.open || argv['open-page']) { + if (argv['open-page']) { options.open = true; options.openPage = argv['open-page']; } + if (typeof argv.open !== 'undefined') { + options.open = argv.open !== '' ? argv.open : true; + } + if (options.open && !options.openPage) { options.openPage = ''; } if (argv.useLocalIp) { options.useLocalIp = true; } @@ -452,9 +456,18 @@ function reportReadiness(uri, options) { if (options.bonjour) { console.log('Broadcasting "http" with subtype of "webpack" via ZeroConf DNS (Bonjour)'); } } + if (options.open) { - open(uri + options.openPage).catch(() => { - console.log('Unable to open browser. If you are running in a headless environment, please do not use the open flag.'); + let openOptions = {}; + let openMessage = 'Unable to open browser'; + + if (typeof options.open === 'string') { + openOptions = { app: options.open }; + openMessage += `: ${options.open}`; + } + + open(uri + (options.openPage || ''), openOptions).catch(() => { + console.log(`${openMessage}. If you are running in a headless environment, please do not use the open flag.`); }); } } diff --git a/lib/optionsSchema.json b/lib/optionsSchema.json index 1f63d7afc9..be1a9cd963 100644 --- a/lib/optionsSchema.json +++ b/lib/optionsSchema.json @@ -200,8 +200,15 @@ "type": "boolean" }, "open": { - "description": "Let the CLI open your browser.", - "type": "boolean" + "description": "Let the CLI open your browser with the URL.", + "anyOf": [ + { + "type": "string" + }, + { + "type": "boolean" + } + ] }, "useLocalIp": { "description": "Let the browser open with your local IP.",