Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit 93779a5

Browse files
aspnet-webpack configures HMR to point directly to http://localhost:<port>/__webpack_hmr instead of proxying via /__webpack_hmr. This is because IE/Edge doesn't honour CORS headers properly following redirects (returns "Network Error 0x80004004"). This could be avoided if we could reverse-proxy to __webpack_hmr (waiting for aspnet/KestrelHttpServer#1139)
1 parent 4fc1d60 commit 93779a5

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/WebpackDevMiddleware.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function arrayContainsStringStartingWith(array: string[], prefixToFind: string)
3030
return array.some(item => item.substring(0, prefixToFind.length) === prefixToFind);
3131
}
3232

33-
function attachWebpackDevMiddleware(app: any, webpackConfig: webpack.Configuration, enableHotModuleReplacement: boolean, enableReactHotModuleReplacement: boolean) {
33+
function attachWebpackDevMiddleware(app: any, webpackConfig: webpack.Configuration, enableHotModuleReplacement: boolean, enableReactHotModuleReplacement: boolean, hmrEndpoint: string) {
3434
// Build the final Webpack config based on supplied options
3535
if (enableHotModuleReplacement) {
3636
// For this, we only support the key/value config format, not string or string[], since
@@ -46,10 +46,11 @@ function attachWebpackDevMiddleware(app: any, webpackConfig: webpack.Configurati
4646
// Augment all entry points so they support HMR (unless they already do)
4747
Object.getOwnPropertyNames(entryPoints).forEach(entryPointName => {
4848
const webpackHotMiddlewareEntryPoint = 'webpack-hot-middleware/client';
49+
const webpackHotMiddlewareOptions = `?path=` + encodeURIComponent(hmrEndpoint);
4950
if (typeof entryPoints[entryPointName] === 'string') {
50-
entryPoints[entryPointName] = [webpackHotMiddlewareEntryPoint, entryPoints[entryPointName]];
51+
entryPoints[entryPointName] = [webpackHotMiddlewareEntryPoint + webpackHotMiddlewareOptions, entryPoints[entryPointName]];
5152
} else if (!arrayContainsStringStartingWith(entryPoints[entryPointName], webpackHotMiddlewareEntryPoint)) {
52-
entryPoints[entryPointName].unshift(webpackHotMiddlewareEntryPoint);
53+
entryPoints[entryPointName].unshift(webpackHotMiddlewareEntryPoint + webpackHotMiddlewareOptions);
5354
}
5455
});
5556

@@ -135,7 +136,9 @@ export function createWebpackDevServer(callback: CreateDevServerCallback, option
135136
throw new Error('To use the Webpack dev server, you must specify a value for \'publicPath\' on the \'output\' section of your webpack config (for any configuration that targets browsers)');
136137
}
137138
normalizedPublicPaths.push(removeTrailingSlash(publicPath));
138-
attachWebpackDevMiddleware(app, webpackConfig, enableHotModuleReplacement, enableReactHotModuleReplacement);
139+
140+
const hmrEndpoint = `http://localhost:${listener.address().port}/__webpack_hmr`;
141+
attachWebpackDevMiddleware(app, webpackConfig, enableHotModuleReplacement, enableReactHotModuleReplacement, hmrEndpoint);
139142
}
140143
});
141144

0 commit comments

Comments
 (0)