Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow --open option to specify the browser to use #825

Merged
merged 18 commits into from
Aug 30, 2017
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
21 changes: 17 additions & 4 deletions bin/webpack-dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ yargs.options({
describe: 'close when stdin ends'
},
open: {
type: 'boolean',
type: 'string',
describe: 'Open default browser'
},
useLocalIp: {
Expand Down Expand Up @@ -324,10 +324,14 @@ 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 = ''; }

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