@@ -21,7 +21,8 @@ module.exports = (api, options) => {
2121 '--mode' : `specify env mode (default: development)` ,
2222 '--host' : `specify host (default: ${ defaults . host } )` ,
2323 '--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`
2526 }
2627 } , async function serve ( args ) {
2728 info ( 'Starting development server...' )
@@ -68,6 +69,7 @@ module.exports = (api, options) => {
6869 const host = args . host || process . env . HOST || projectDevServerOptions . host || defaults . host
6970 portfinder . basePort = args . port || process . env . PORT || projectDevServerOptions . port || defaults . port
7071 const port = await portfinder . getPortPromise ( )
72+ const publicUrl = args . public || projectDevServerOptions . public
7173
7274 const urls = prepareURLs (
7375 protocol ,
@@ -83,8 +85,7 @@ module.exports = (api, options) => {
8385
8486 // inject dev & hot-reload middleware entries
8587 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 ( {
8889 protocol,
8990 port,
9091 hostname : urls . lanUrlForConfig || 'localhost' ,
@@ -181,11 +182,14 @@ module.exports = (api, options) => {
181182 copied = chalk . dim ( '(copied to clipboard)' )
182183 }
183184
185+ const networkUrl = publicUrl
186+ ? ( protocol + '://' + publicUrl ) . replace ( / ( [ ^ / ] ) $ / , '$1/' )
187+ : urls . lanUrlForTerminal
184188 console . log ( )
185189 console . log ( [
186190 ` App running at:` ,
187191 ` - Local: ${ chalk . cyan ( urls . localUrlForTerminal ) } ${ copied } ` ,
188- ` - Network: ${ chalk . cyan ( urls . lanUrlForTerminal ) } `
192+ ` - Network: ${ chalk . cyan ( networkUrl ) } `
189193 ] . join ( '\n' ) )
190194 console . log ( )
191195
0 commit comments