@@ -22,6 +22,7 @@ process.env.NODE_ENV = 'development';
22
22
// Ensure environment variables are read.
23
23
require ( '../config/env' ) ;
24
24
25
+ const address = require ( 'address' ) ;
25
26
const fs = require ( 'fs' ) ;
26
27
const chalk = require ( 'chalk' ) ;
27
28
const detect = require ( '@timer/detect-port' ) ;
@@ -53,25 +54,23 @@ const HOST = process.env.HOST || '0.0.0.0';
53
54
54
55
function run ( port ) {
55
56
const protocol = process . env . HTTPS === 'true' ? 'https' : 'http' ;
56
- const formattedUrl = url . format ( {
57
- protocol,
58
- hostname : HOST ,
59
- port,
60
- pathname : '/' ,
61
- } ) ;
62
57
63
- let prettyHost ;
64
- if ( HOST === '0.0.0.0' || HOST === '::' ) {
58
+ const formatUrl = hostname =>
59
+ url . format ( { protocol, hostname, port, pathname : '/' } ) ;
60
+
61
+ const isUnspecifiedAddress = HOST === '0.0.0.0' || HOST === '::' ;
62
+ let prettyHost , lanAddress ;
63
+ if ( isUnspecifiedAddress ) {
65
64
prettyHost = 'localhost' ;
65
+ try {
66
+ lanAddress = address . ip ( ) ;
67
+ } catch ( _e ) {
68
+ // ignored
69
+ }
66
70
} else {
67
71
prettyHost = HOST ;
68
72
}
69
- const prettyUrl = url . format ( {
70
- protocol,
71
- hostname : prettyHost ,
72
- port,
73
- pathname : '/' ,
74
- } ) ;
73
+ const prettyUrl = formatUrl ( prettyHost ) ;
75
74
76
75
// Create a webpack compiler that is configured with custom messages.
77
76
const compiler = createWebpackCompiler (
@@ -81,9 +80,22 @@ function run(port) {
81
80
return ;
82
81
}
83
82
console . log ( ) ;
84
- console . log ( 'The app is running at:' ) ;
83
+ console . log (
84
+ `You can now view ${ chalk . bold ( require ( paths . appPackageJson ) . name ) } in the browser.`
85
+ ) ;
85
86
console . log ( ) ;
86
- console . log ( ` ${ chalk . cyan ( formattedUrl ) } ` ) ;
87
+
88
+ if ( isUnspecifiedAddress && lanAddress ) {
89
+ console . log (
90
+ ` ${ chalk . bold ( 'Local:' ) } ${ chalk . cyan ( prettyUrl ) } `
91
+ ) ;
92
+ console . log (
93
+ ` ${ chalk . bold ( 'On Your Network:' ) } ${ chalk . cyan ( formatUrl ( lanAddress ) ) } `
94
+ ) ;
95
+ } else {
96
+ console . log ( ` ${ chalk . cyan ( prettyUrl ) } ` ) ;
97
+ }
98
+
87
99
console . log ( ) ;
88
100
console . log ( 'Note that the development build is not optimized.' ) ;
89
101
console . log (
@@ -98,7 +110,7 @@ function run(port) {
98
110
// Serve webpack assets generated by the compiler over a web sever.
99
111
const devServer = new WebpackDevServer (
100
112
compiler ,
101
- devServerConfig ( prepareProxy ( proxy ) )
113
+ devServerConfig ( prepareProxy ( proxy ) , lanAddress )
102
114
) ;
103
115
104
116
// Launch WebpackDevServer.
@@ -113,7 +125,7 @@ function run(port) {
113
125
console . log ( chalk . cyan ( 'Starting the development server...' ) ) ;
114
126
console . log ( ) ;
115
127
116
- openBrowser ( prettyUrl ) ;
128
+ openBrowser ( formatUrl ( prettyHost ) ) ;
117
129
} ) ;
118
130
}
119
131
0 commit comments