File tree Expand file tree Collapse file tree 3 files changed +19
-9
lines changed Expand file tree Collapse file tree 3 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -281,8 +281,15 @@ function processOptions(wpOpt) {
281
281
282
282
var protocol = options . https ? "https" : "http" ;
283
283
284
+ // the formated domain (url without path) of the webpack server
285
+ var domain = url . format ( {
286
+ protocol : protocol ,
287
+ hostname : options . host ,
288
+ port : options . socket ? 0 : options . port . toString ( )
289
+ } ) ;
290
+
284
291
if ( options . inline !== false ) {
285
- var devClient = [ require . resolve ( "../client/" ) + "?" + protocol + "://" + ( options . public || ( options . host + ":" + options . port ) ) ] ;
292
+ var devClient = [ require . resolve ( "../client/" ) + "?" + ( options . public ? protocol + "://" + options . public : domain ) ] ;
286
293
287
294
if ( options . hotOnly )
288
295
devClient . push ( "webpack/hot/only-dev-server" ) ;
@@ -308,12 +315,7 @@ function processOptions(wpOpt) {
308
315
} ) ) ;
309
316
}
310
317
311
- var uri = url . format ( {
312
- protocol : protocol ,
313
- hostname : options . host ,
314
- pathname : options . inline !== false ? "/" : "webpack-dev-server/" ,
315
- port : options . socket ? 0 : options . port . toString ( )
316
- } ) ;
318
+ var uri = domain + ( options . inline !== false ? "/" : "webpack-dev-server/" ) ;
317
319
318
320
var server = new Server ( compiler , options ) ;
319
321
Original file line number Diff line number Diff line change @@ -89,7 +89,9 @@ var onSocketMsg = {
89
89
var hostname = urlParts . hostname ;
90
90
var protocol = urlParts . protocol ;
91
91
92
- if ( urlParts . hostname === "0.0.0.0" ) {
92
+
93
+ //check ipv4 and ipv6 `all hostname`
94
+ if ( hostname === "0.0.0.0" || hostname === "::" ) {
93
95
// why do we need this check?
94
96
// hostname n/a for file protocol (example, when using electron, ionic)
95
97
// see: https://github.com/webpack/webpack-dev-server/pull/384
Original file line number Diff line number Diff line change 1
1
# host and port
2
2
3
+ Only For ipv4
3
4
``` shell
4
5
node ../../bin/webpack-dev-server.js --open --port 5000 --host 0.0.0.0
5
6
```
6
7
8
+ For ipv6 support. (it also works with ipv4.)
9
+ ``` shell
10
+ node ../../bin/webpack-dev-server.js --open --port 5000 --host ::
11
+ ```
12
+
7
13
We want to change the port to ` 5000 ` , and make the server publicly accessible.
8
14
9
15
## What should happen
10
16
11
- The script should open ` http://0.0.0.0:5000/ ` . You should see "It's working."
17
+ The script should open ` http://0.0.0.0:5000/ ` (ipv4) or ` http://[::]:5000/ ` (ipv6) . You should see "It's working."
12
18
13
19
Get your local ip (e.g. ` 192.168.1.40 ` ), and try it from ` 192.168.1.40:5000 ` . Make sure your firewall doesn't block this port.
You can’t perform that action at this time.
0 commit comments