@@ -21,7 +21,8 @@ module.exports = (api, options) => {
21
21
'--mode' : `specify env mode (default: development)` ,
22
22
'--host' : `specify host (default: ${ defaults . host } )` ,
23
23
'--port' : `specify port (default: ${ defaults . port } )` ,
24
- '--https' : `use https (default: ${ defaults . https } )`
24
+ '--https' : `use https (default: ${ defaults . https } )` ,
25
+ '--public' : `specify the public network URL for the HMR client`
25
26
}
26
27
} , async function serve ( args ) {
27
28
info ( 'Starting development server...' )
@@ -68,6 +69,7 @@ module.exports = (api, options) => {
68
69
const host = args . host || process . env . HOST || projectDevServerOptions . host || defaults . host
69
70
portfinder . basePort = args . port || process . env . PORT || projectDevServerOptions . port || defaults . port
70
71
const port = await portfinder . getPortPromise ( )
72
+ const publicUrl = args . public || projectDevServerOptions . public
71
73
72
74
const urls = prepareURLs (
73
75
protocol ,
@@ -83,8 +85,7 @@ module.exports = (api, options) => {
83
85
84
86
// inject dev & hot-reload middleware entries
85
87
if ( ! isProduction ) {
86
- const publicOpt = projectDevServerOptions . public
87
- const sockjsUrl = publicOpt ? `//${ publicOpt } /sockjs-node` : url . format ( {
88
+ const sockjsUrl = publicUrl ? `//${ publicUrl } /sockjs-node` : url . format ( {
88
89
protocol,
89
90
port,
90
91
hostname : urls . lanUrlForConfig || 'localhost' ,
@@ -181,11 +182,14 @@ module.exports = (api, options) => {
181
182
copied = chalk . dim ( '(copied to clipboard)' )
182
183
}
183
184
185
+ const networkUrl = publicUrl
186
+ ? ( protocol + '://' + publicUrl ) . replace ( / ( [ ^ / ] ) $ / , '$1/' )
187
+ : urls . lanUrlForTerminal
184
188
console . log ( )
185
189
console . log ( [
186
190
` App running at:` ,
187
191
` - Local: ${ chalk . cyan ( urls . localUrlForTerminal ) } ${ copied } ` ,
188
- ` - Network: ${ chalk . cyan ( urls . lanUrlForTerminal ) } `
192
+ ` - Network: ${ chalk . cyan ( networkUrl ) } `
189
193
] . join ( '\n' ) )
190
194
console . log ( )
191
195
0 commit comments