Skip to content

Commit

Permalink
Merge pull request #329 from CodeYellowBV/open-browser
Browse files Browse the repository at this point in the history
Open default browser if --open option is given
  • Loading branch information
sokra committed Jan 11, 2016
2 parents e85e8f6 + 98fd2f4 commit 83cff95
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
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 @@ -46,8 +47,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 @@ -147,6 +151,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 @@ -166,16 +173,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 @@ -11,6 +11,7 @@
"connect-history-api-fallback": "1.1.0",
"express": "^4.13.3",
"optimist": "~0.6.0",
"open": "0.0.5",
"serve-index": "^1.7.2",
"sockjs": "^0.3.15",
"sockjs-client": "^1.0.3",
Expand Down

0 comments on commit 83cff95

Please sign in to comment.