@@ -12,9 +12,21 @@ class ErrorOverlayPlugin {
1212 const devServerEnabled = ! ! compiler . options . devServer
1313 const sockOptions = { }
1414 if ( devServerEnabled ) {
15- sockOptions . sockHost = compiler . options . devServer . sockHost
16- sockOptions . sockPath = compiler . options . devServer . sockPath
17- sockOptions . sockPort = compiler . options . devServer . sockPort
15+ // In the webpack config it's possible to override the websocket server's
16+ // connect URL for clients that need to connect through a proxy or other means.
17+ //
18+ // Use a webSocketURL config if present, otherwise default to the same address
19+ // as the devServer:
20+ sockOptions . sockHost =
21+ compiler . options . devServer . client ?. webSocketURL ?. hostname ||
22+ compiler . options . devServer . host
23+ sockOptions . sockPath =
24+ compiler . options . devServer . client ?. webSocketURL ?. pathname ||
25+ compiler . options . devServer . webSocketServer ?. options . path ||
26+ '/ws'
27+ sockOptions . sockPort =
28+ compiler . options . devServer . client ?. webSocketURL ?. port ||
29+ compiler . options . devServer . port
1830 }
1931
2032 compiler . hooks . entryOption . tap ( className , ( context , entry ) => {
@@ -23,12 +35,13 @@ class ErrorOverlayPlugin {
2335
2436 compiler . hooks . afterResolvers . tap ( className , ( { options } ) => {
2537 if ( devServerEnabled ) {
26- const originalBefore = options . devServer . before
27- options . devServer . before = ( app , server ) => {
28- if ( originalBefore ) {
29- originalBefore ( app , server , compiler )
38+ const originalOnBeforeSetupMiddleware =
39+ options . devServer . onBeforeSetupMiddleware
40+ options . devServer . onBeforeSetupMiddleware = ( devServer ) => {
41+ if ( originalOnBeforeSetupMiddleware ) {
42+ originalOnBeforeSetupMiddleware ( devServer )
3043 }
31- app . use ( errorOverlayMiddleware ( ) )
44+ devServer . app . use ( errorOverlayMiddleware ( ) )
3245 }
3346 }
3447 } )
0 commit comments