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 7 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
9 changes: 7 additions & 2 deletions bin/webpack-dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ yargs.options({
describe: "close when stdin ends"
},
"open": {
type: "boolean",
type: "string",
describe: "Open default browser"
},
"color": {
Expand Down Expand Up @@ -311,7 +311,7 @@ function processOptions(wpOpt) {
options.compress = true;

if(argv["open"])
options.open = true;
options.open = (argv["open"] === "") ? true : argv["open"];

// Kind of weird, but ensures prior behavior isn't broken in cases
// that wouldn't throw errors. E.g. both argv.port and options.port
Expand Down Expand Up @@ -421,6 +421,11 @@ function reportReadiness(uri, options) {
if(options.historyApiFallback)
console.log(`404s will fallback to ${colorInfo(useColor, options.historyApiFallback.index || "/index.html")}`);
if(options.open) {
open(uri, { app: options.open }).catch(function() {
console.log(`Unable to open browser '${options.open}'. If you are running in a headless environment, please do not use the open flag.`);
});
}
if(argv["open"] === "") {
open(uri).catch(function() {
console.log("Unable to open browser. If you are running in a headless environment, please do not use the open flag.");
});
Expand Down
9 changes: 8 additions & 1 deletion lib/optionsSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,14 @@
},
"open": {
"description": "Let the CLI open your browser with the URL.",
"type": "boolean"
"anyOf": [
{
"type": "string"
},
{
"type": "boolean"
}
]
},
"features": {
"description": "The order of which the features will be triggered.",
Expand Down