mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 01:58:29 +00:00
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 https://github.com/aspnet/KestrelHttpServer/issues/1139)
This commit is contained in:
@@ -30,7 +30,7 @@ function arrayContainsStringStartingWith(array: string[], prefixToFind: string)
|
|||||||
return array.some(item => item.substring(0, prefixToFind.length) === prefixToFind);
|
return array.some(item => item.substring(0, prefixToFind.length) === prefixToFind);
|
||||||
}
|
}
|
||||||
|
|
||||||
function attachWebpackDevMiddleware(app: any, webpackConfig: webpack.Configuration, enableHotModuleReplacement: boolean, enableReactHotModuleReplacement: boolean) {
|
function attachWebpackDevMiddleware(app: any, webpackConfig: webpack.Configuration, enableHotModuleReplacement: boolean, enableReactHotModuleReplacement: boolean, hmrEndpoint: string) {
|
||||||
// Build the final Webpack config based on supplied options
|
// Build the final Webpack config based on supplied options
|
||||||
if (enableHotModuleReplacement) {
|
if (enableHotModuleReplacement) {
|
||||||
// For this, we only support the key/value config format, not string or string[], since
|
// 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
|
|||||||
// Augment all entry points so they support HMR (unless they already do)
|
// Augment all entry points so they support HMR (unless they already do)
|
||||||
Object.getOwnPropertyNames(entryPoints).forEach(entryPointName => {
|
Object.getOwnPropertyNames(entryPoints).forEach(entryPointName => {
|
||||||
const webpackHotMiddlewareEntryPoint = 'webpack-hot-middleware/client';
|
const webpackHotMiddlewareEntryPoint = 'webpack-hot-middleware/client';
|
||||||
|
const webpackHotMiddlewareOptions = `?path=` + encodeURIComponent(hmrEndpoint);
|
||||||
if (typeof entryPoints[entryPointName] === 'string') {
|
if (typeof entryPoints[entryPointName] === 'string') {
|
||||||
entryPoints[entryPointName] = [webpackHotMiddlewareEntryPoint, entryPoints[entryPointName]];
|
entryPoints[entryPointName] = [webpackHotMiddlewareEntryPoint + webpackHotMiddlewareOptions, entryPoints[entryPointName]];
|
||||||
} else if (!arrayContainsStringStartingWith(entryPoints[entryPointName], webpackHotMiddlewareEntryPoint)) {
|
} else if (!arrayContainsStringStartingWith(entryPoints[entryPointName], webpackHotMiddlewareEntryPoint)) {
|
||||||
entryPoints[entryPointName].unshift(webpackHotMiddlewareEntryPoint);
|
entryPoints[entryPointName].unshift(webpackHotMiddlewareEntryPoint + webpackHotMiddlewareOptions);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -135,7 +136,9 @@ export function createWebpackDevServer(callback: CreateDevServerCallback, option
|
|||||||
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)');
|
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)');
|
||||||
}
|
}
|
||||||
normalizedPublicPaths.push(removeTrailingSlash(publicPath));
|
normalizedPublicPaths.push(removeTrailingSlash(publicPath));
|
||||||
attachWebpackDevMiddleware(app, webpackConfig, enableHotModuleReplacement, enableReactHotModuleReplacement);
|
|
||||||
|
const hmrEndpoint = `http://localhost:${listener.address().port}/__webpack_hmr`;
|
||||||
|
attachWebpackDevMiddleware(app, webpackConfig, enableHotModuleReplacement, enableReactHotModuleReplacement, hmrEndpoint);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user