@@ -55,22 +55,35 @@ const HOST = process.env.HOST || '0.0.0.0';
55
55
function run ( port ) {
56
56
const protocol = process . env . HTTPS === 'true' ? 'https' : 'http' ;
57
57
58
- const formatUrl = hostname =>
59
- url . format ( { protocol, hostname, port, pathname : '/' } ) ;
58
+ const formatUrl = hostname => url . format ( {
59
+ protocol,
60
+ hostname,
61
+ port,
62
+ pathname : '/' ,
63
+ } ) ;
64
+ const prettyPrintUrl = hostname => url . format ( {
65
+ protocol,
66
+ hostname,
67
+ port : chalk . bold ( port ) ,
68
+ pathname : '/' ,
69
+ } ) ;
60
70
61
71
const isUnspecifiedAddress = HOST === '0.0.0.0' || HOST === '::' ;
62
- let prettyHost , lanAddress ;
72
+ let prettyHost , lanAddress , prettyLanUrl ;
63
73
if ( isUnspecifiedAddress ) {
64
74
prettyHost = 'localhost' ;
65
75
try {
66
76
lanAddress = address . ip ( ) ;
77
+ if ( lanAddress ) {
78
+ prettyLanUrl = prettyPrintUrl ( lanAddress ) ;
79
+ }
67
80
} catch ( _e ) {
68
81
// ignored
69
82
}
70
83
} else {
71
84
prettyHost = HOST ;
72
85
}
73
- const prettyUrl = formatUrl ( prettyHost ) ;
86
+ const prettyLocalUrl = prettyPrintUrl ( prettyHost ) ;
74
87
75
88
// Create a webpack compiler that is configured with custom messages.
76
89
const compiler = createWebpackCompiler (
@@ -85,15 +98,11 @@ function run(port) {
85
98
) ;
86
99
console . log ( ) ;
87
100
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
- ) ;
101
+ if ( prettyLanUrl ) {
102
+ console . log ( ` ${ chalk . bold ( 'Local:' ) } ${ prettyLocalUrl } ` ) ;
103
+ console . log ( ` ${ chalk . bold ( 'On Your Network:' ) } ${ prettyLanUrl } ` ) ;
95
104
} else {
96
- console . log ( ` ${ chalk . cyan ( prettyUrl ) } ` ) ;
105
+ console . log ( ` ${ prettyLocalUrl } ` ) ;
97
106
}
98
107
99
108
console . log ( ) ;
0 commit comments