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

Open default browser if --open option is given #329

Merged
merged 2 commits into from
Jan 11, 2016
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
18 changes: 14 additions & 4 deletions bin/webpack-dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var path = require("path");
var url = require("url");
var open = require("open");
var fs = require("fs");

// Local version replaces global one
Expand Down Expand Up @@ -44,8 +45,11 @@ var optimist = require("optimist")

.boolean("compress").describe("compress", "enable gzip compression")

.boolean("open").describe("open", "Open default browser")

.describe("port", "The port").default("port", 8080)


.describe("host", "The hostname/ip address the server will bind to").default("host", "localhost");

require("webpack/bin/config-optimist")(optimist);
Expand Down Expand Up @@ -137,6 +141,9 @@ if(argv["history-api-fallback"])
if(argv["compress"])
options.compress = true;

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

var protocol = options.https ? "https" : "http";

if(options.inline) {
Expand All @@ -156,16 +163,19 @@ if(options.inline) {
}

new Server(webpack(wpOpt), options).listen(options.port, options.host, function(err) {
var uri = protocol + "://" + options.host + ":" + options.port + "/";
if(!options.inline)
uri += "webpack-dev-server/";

if(err) throw err;
if(options.inline)
console.log(protocol + "://" + options.host + ":" + options.port + "/");
else
console.log(protocol + "://" + options.host + ":" + options.port + "/webpack-dev-server/");
console.log(uri);
console.log("webpack result is served from " + options.publicPath);
if(typeof options.contentBase === "object")
console.log("requests are proxied to " + options.contentBase.target);
else
console.log("content is served from " + options.contentBase);
if(options.historyApiFallback)
console.log("404s will fallback to %s", options.historyApiFallback.index || "/index.html");
if (options.open)
open(uri);
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"express": "^4.13.3",
"http-proxy": "^1.11.2",
"optimist": "~0.6.0",
"open": "0.0.5",
"serve-index": "^1.7.2",
"sockjs": "^0.3.15",
"sockjs-client": "^1.0.3",
Expand Down