Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ node_modules
/client/sockjs.bundle.js
/coverage
*.pem
.idea/
/package-lock.json
23 changes: 18 additions & 5 deletions bin/webpack-dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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.`);
});
}
}
Expand Down
11 changes: 9 additions & 2 deletions lib/optionsSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down