@@ -23,11 +23,13 @@ interface CreateDevServerOptions {
23
23
hotModuleReplacementEndpointUrl : string ;
24
24
}
25
25
26
+ type StringMap < T > = [ ( key : string ) => T ] ;
27
+
26
28
// These are the options configured in C# and then JSON-serialized, hence the C#-style naming
27
29
interface DevServerOptions {
28
30
HotModuleReplacement : boolean ;
29
31
HotModuleReplacementServerPort : number ;
30
- HotModuleReplacementClientOptions : Object ;
32
+ HotModuleReplacementClientOptions : StringMap < string > ;
31
33
ReactHotModuleReplacement : boolean ;
32
34
}
33
35
@@ -39,7 +41,7 @@ interface WebpackConfigFunc {
39
41
}
40
42
type WebpackConfigFileExport = WebpackConfigOrArray | WebpackConfigFunc ;
41
43
42
- function attachWebpackDevMiddleware ( app : any , webpackConfig : webpack . Configuration , enableHotModuleReplacement : boolean , enableReactHotModuleReplacement : boolean , hmrClientOptions : HotModuleReplacementClientOptions , hmrClientEndpoint : string , hmrServerEndpoint : string ) {
44
+ function attachWebpackDevMiddleware ( app : any , webpackConfig : webpack . Configuration , enableHotModuleReplacement : boolean , enableReactHotModuleReplacement : boolean , hmrClientOptions : StringMap < string > , hmrServerEndpoint : string ) {
43
45
// Build the final Webpack config based on supplied options
44
46
if ( enableHotModuleReplacement ) {
45
47
// For this, we only support the key/value config format, not string or string[], since
@@ -55,7 +57,6 @@ function attachWebpackDevMiddleware(app: any, webpackConfig: webpack.Configurati
55
57
// Augment all entry points so they support HMR (unless they already do)
56
58
Object . getOwnPropertyNames ( entryPoints ) . forEach ( entryPointName => {
57
59
const webpackHotMiddlewareEntryPoint = 'webpack-hot-middleware/client' ;
58
- hmrClientOptions . path = hmrClientEndpoint ;
59
60
const webpackHotMiddlewareOptions = '?' + querystring . stringify ( hmrClientOptions ) ;
60
61
if ( typeof entryPoints [ entryPointName ] === 'string' ) {
61
62
entryPoints [ entryPointName ] = [ webpackHotMiddlewareEntryPoint + webpackHotMiddlewareOptions , entryPoints [ entryPointName ] ] ;
@@ -228,7 +229,6 @@ export function createWebpackDevServer(callback: CreateDevServerCallback, option
228
229
229
230
const enableHotModuleReplacement = options . suppliedOptions . HotModuleReplacement ;
230
231
const enableReactHotModuleReplacement = options . suppliedOptions . ReactHotModuleReplacement ;
231
- const hmrClientOptions = options . suppliedOptions . HotModuleReplacementClientOptions || { } ;
232
232
if ( enableReactHotModuleReplacement && ! enableHotModuleReplacement ) {
233
233
callback ( 'To use ReactHotModuleReplacement, you must also enable the HotModuleReplacement option.' , null ) ;
234
234
return ;
@@ -267,7 +267,12 @@ export function createWebpackDevServer(callback: CreateDevServerCallback, option
267
267
|| `http://localhost:${ listener . address ( ) . port } /__webpack_hmr` ; // Fall back on absolute URL to bypass proxying
268
268
const hmrServerEndpoint = options . hotModuleReplacementEndpointUrl
269
269
|| '/__webpack_hmr' ; // URL is relative to webpack dev server root
270
- attachWebpackDevMiddleware ( app , webpackConfig , enableHotModuleReplacement , enableReactHotModuleReplacement , hmrClientOptions , hmrClientEndpoint , hmrServerEndpoint ) ;
270
+
271
+ // We always overwrite the 'path' option as it needs to match what the .NET side is expecting
272
+ const hmrClientOptions = options . suppliedOptions . HotModuleReplacementClientOptions || < StringMap < string > > { } ;
273
+ hmrClientOptions [ 'path' ] = hmrClientEndpoint ;
274
+
275
+ attachWebpackDevMiddleware ( app , webpackConfig , enableHotModuleReplacement , enableReactHotModuleReplacement , hmrClientOptions , hmrServerEndpoint ) ;
271
276
}
272
277
} ) ;
273
278
0 commit comments