@@ -22,6 +22,7 @@ process.env.NODE_ENV = 'development';
2222// Ensure environment variables are read.
2323require ( '../config/env' ) ;
2424
25+ const address = require ( 'address' ) ;
2526const fs = require ( 'fs' ) ;
2627const chalk = require ( 'chalk' ) ;
2728const detect = require ( '@timer/detect-port' ) ;
@@ -53,25 +54,23 @@ const HOST = process.env.HOST || '0.0.0.0';
5354
5455function run ( port ) {
5556 const protocol = process . env . HTTPS === 'true' ? 'https' : 'http' ;
56- const formattedUrl = url . format ( {
57- protocol,
58- hostname : HOST ,
59- port,
60- pathname : '/' ,
61- } ) ;
6257
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 ) {
6564 prettyHost = 'localhost' ;
65+ try {
66+ lanAddress = address . ip ( ) ;
67+ } catch ( _e ) {
68+ // ignored
69+ }
6670 } else {
6771 prettyHost = HOST ;
6872 }
69- const prettyUrl = url . format ( {
70- protocol,
71- hostname : prettyHost ,
72- port,
73- pathname : '/' ,
74- } ) ;
73+ const prettyUrl = formatUrl ( prettyHost ) ;
7574
7675 // Create a webpack compiler that is configured with custom messages.
7776 const compiler = createWebpackCompiler (
@@ -81,9 +80,22 @@ function run(port) {
8180 return ;
8281 }
8382 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+ ) ;
8586 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+
8799 console . log ( ) ;
88100 console . log ( 'Note that the development build is not optimized.' ) ;
89101 console . log (
@@ -98,7 +110,7 @@ function run(port) {
98110 // Serve webpack assets generated by the compiler over a web sever.
99111 const devServer = new WebpackDevServer (
100112 compiler ,
101- devServerConfig ( prepareProxy ( proxy ) )
113+ devServerConfig ( prepareProxy ( proxy ) , lanAddress )
102114 ) ;
103115
104116 // Launch WebpackDevServer.
@@ -113,7 +125,7 @@ function run(port) {
113125 console . log ( chalk . cyan ( 'Starting the development server...' ) ) ;
114126 console . log ( ) ;
115127
116- openBrowser ( prettyUrl ) ;
128+ openBrowser ( formatUrl ( prettyHost ) ) ;
117129 } ) ;
118130}
119131
0 commit comments