@@ -18,19 +18,52 @@ function getAdditionalEntries({ devServer, options }) {
1818 let resourceQuery = { } ;
1919
2020 if ( devServer ) {
21- const { sockHost, sockPath, sockPort, host, path, port, https, http2 } = devServer ;
21+ const { client, https, http2, sockHost, sockPath, sockPort } = devServer ;
22+ let { host, path, port } = devServer ;
2223
23- ( sockHost || host ) && ( resourceQuery . sockHost = sockHost ? sockHost : host ) ;
24- ( sockPath || path ) && ( resourceQuery . sockPath = sockPath ? sockPath : path ) ;
25- ( sockPort || port ) && ( resourceQuery . sockPort = sockPort ? sockPort : port ) ;
26- resourceQuery . sockProtocol = https || http2 ? 'https' : 'http' ;
24+ let protocol = https || http2 ? 'https' : 'http' ;
25+ if ( sockHost ) host = sockHost ;
26+ if ( sockPath ) path = sockPath ;
27+ if ( sockPort ) port = sockPort ;
28+
29+ if ( client && client . webSocketURL != null ) {
30+ let parsedUrl = client . webSocketURL ;
31+ if ( typeof parsedUrl === 'string' ) parsedUrl = new URL ( parsedUrl ) ;
32+
33+ let auth ;
34+ if ( parsedUrl . username ) {
35+ auth = parsedUrl . username ;
36+ if ( parsedUrl . password ) {
37+ auth += ':' + parsedUrl . password ;
38+ }
39+ }
40+
41+ if ( parsedUrl . hostname != null ) {
42+ host = [ auth != null && auth , parsedUrl . hostname ] . filter ( Boolean ) . join ( '@' ) ;
43+ }
44+ if ( parsedUrl . pathname != null ) {
45+ path = parsedUrl . pathname ;
46+ }
47+ if ( parsedUrl . port != null ) {
48+ port = String ( parsedUrl . port ) !== '0' ? parsedUrl . port : undefined ;
49+ }
50+ if ( parsedUrl . protocol != null ) {
51+ protocol = parsedUrl . protocol !== 'auto' ? parsedUrl . protocol . replace ( ':' , '' ) : 'ws' ;
52+ }
53+ }
54+
55+ if ( host ) resourceQuery . sockHost = host ;
56+ if ( path ) resourceQuery . sockPath = path ;
57+ if ( port ) resourceQuery . sockPort = port ;
58+ resourceQuery . sockProtocol = protocol ;
2759 }
2860
2961 if ( options . overlay ) {
30- options . overlay . sockHost && ( resourceQuery . sockHost = options . overlay . sockHost ) ;
31- options . overlay . sockPath && ( resourceQuery . sockPath = options . overlay . sockPath ) ;
32- options . overlay . sockPort && ( resourceQuery . sockPort = options . overlay . sockPort ) ;
33- options . overlay . sockProtocol && ( resourceQuery . sockProtocol = options . overlay . sockProtocol ) ;
62+ const { sockHost, sockPath, sockPort, sockProtocol } = options . overlay ;
63+ if ( sockHost ) resourceQuery . sockHost = sockHost ;
64+ if ( sockPath ) resourceQuery . sockPath = sockPath ;
65+ if ( sockPort ) resourceQuery . sockPort = sockPort ;
66+ if ( sockProtocol ) resourceQuery . sockProtocol = sockProtocol ;
3467 }
3568
3669 // We don't need to URI encode the resourceQuery as it will be parsed by Webpack
0 commit comments