@@ -32,6 +32,7 @@ module.exports = (api, options) => {
32
32
const isInContainer = checkInContainer ( )
33
33
const isProduction = process . env . NODE_ENV === 'production'
34
34
35
+ const url = require ( 'url' )
35
36
const path = require ( 'path' )
36
37
const chalk = require ( 'chalk' )
37
38
const webpack = require ( 'webpack' )
@@ -91,8 +92,19 @@ module.exports = (api, options) => {
91
92
// inject dev & hot-reload middleware entries
92
93
if ( ! isProduction ) {
93
94
const sockjsUrl = publicUrl
95
+ // explicitly configured via devServer.public
94
96
? `?${ publicUrl } /sockjs-node`
95
- : ``
97
+ : isInContainer
98
+ // can't infer public netowrk url if inside a container...
99
+ // use client-side inference (note this would break with non-root baseUrl)
100
+ ? ``
101
+ // otherwise infer the url
102
+ : `?` + url . format ( {
103
+ protocol,
104
+ port,
105
+ hostname : urls . lanUrlForConfig || 'localhost' ,
106
+ pathname : '/sockjs-node'
107
+ } )
96
108
const devClients = [
97
109
// dev server client
98
110
require . resolve ( `webpack-dev-server/client` ) + sockjsUrl ,
@@ -195,7 +207,16 @@ module.exports = (api, options) => {
195
207
} else {
196
208
console . log ( )
197
209
console . log ( chalk . yellow ( ` It seems you are running Vue CLI inside a container.` ) )
198
- console . log ( chalk . yellow ( ` Access the dev server via ${ protocol } ://localhost:<your container's external mapped port>.` ) )
210
+ if ( ! publicUrl && options . baseUrl && options . baseUrl !== '/' ) {
211
+ console . log ( )
212
+ console . log ( chalk . yellow ( ` Since you are using a non-root baseUrl, the hot-reload socket` ) )
213
+ console . log ( chalk . yellow ( ` will not be able to infer the correct URL to connect. You should` ) )
214
+ console . log ( chalk . yellow ( ` explicitly specify the URL via ${ chalk . blue ( `devServer.public` ) } .` ) )
215
+ console . log ( )
216
+ }
217
+ console . log ( chalk . yellow ( ` Access the dev server via ${ chalk . cyan (
218
+ `${ protocol } ://localhost:<your container's external mapped port>${ options . baseUrl } `
219
+ ) } `) )
199
220
}
200
221
console . log ( )
201
222
0 commit comments