Skip to content

Commit

Permalink
Add 'lan' option (modify the option name to ‘useLocalIp’ for more sem…
Browse files Browse the repository at this point in the history
…antic) (#901)

* Add 'lan' option

  Let the browser open with local IP.

* Add 'lan' option

  Let the browser open with local IP.

* extract function getLocalIP and add some tests.

* Change the option name to 'useLocalIp' and use 'internal-ip' to get local ip.

* Fix confilcts.
  • Loading branch information
sliwey authored and shellscape committed Jun 18, 2017
1 parent 8d5f252 commit 7b3a42a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
7 changes: 7 additions & 0 deletions bin/webpack-dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ yargs.options({
type: "boolean",
describe: "Open default browser"
},
"useLocalIp": {
type: "boolean",
describe: "Open default browser with local IP"
},
"open-page": {
type: "string",
describe: "Open default browser with the specified page",
Expand Down Expand Up @@ -330,6 +334,9 @@ function processOptions(wpOpt) {
options.openPage = argv["open-page"] || "";
}

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

// 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
// were specified, but since argv.port is 8080, options.port will be
Expand Down
4 changes: 4 additions & 0 deletions lib/optionsSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@
"description": "Let the CLI open your browser.",
"type": "boolean"
},
"useLocalIp": {
"description": "Let the browser open with your local IP.",
"type": "boolean"
},
"openPage": {
"description": "Let the CLI open your browser to a specific page on the site.",
"type": "string"
Expand Down
3 changes: 2 additions & 1 deletion lib/util/createDomain.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"use strict";
const url = require("url");
const internalIp = require("internal-ip");

module.exports = function createDomain(options) {
const protocol = options.https ? "https" : "http";

// the formatted domain (url without path) of the webpack server
return options.public ? `${protocol}://${options.public}` : url.format({
protocol: protocol,
hostname: options.host,
hostname: options.useLocalIp ? internalIp.v4() : options.host,
port: options.socket ? 0 : options.port.toString()
});
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"express": "^4.13.3",
"html-entities": "^1.2.0",
"http-proxy-middleware": "~0.17.4",
"internal-ip": "^1.2.0",
"opn": "4.0.2",
"portfinder": "^1.0.9",
"selfsigned": "^1.9.1",
Expand Down
2 changes: 1 addition & 1 deletion test/Validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe("Validation", function() {
" - configuration has an unknown property 'asdf'. These properties are valid:",
" object { hot?, hotOnly?, lazy?, bonjour?, host?, allowedHosts?, filename?, publicPath?, port?, socket?, " +
"watchOptions?, headers?, clientLogLevel?, overlay?, key?, cert?, ca?, pfx?, pfxPassphrase?, " +
"inline?, disableHostCheck?, public?, https?, contentBase?, watchContentBase?, open?, openPage?, features?, " +
"inline?, disableHostCheck?, public?, https?, contentBase?, watchContentBase?, open?, useLocalIp?, openPage?, features?, " +
"compress?, proxy?, historyApiFallback?, staticOptions?, setup?, stats?, reporter?, " +
"noInfo?, quiet?, serverSideRender?, index?, log?, warn? }"
]
Expand Down

0 comments on commit 7b3a42a

Please sign in to comment.