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

Commit

Permalink
aspnet-webpack configures HMR to point directly to http://localhost:<…
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
SteveSandersonMS committed Oct 10, 2016
1 parent 4fc1d60 commit 93779a5
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function arrayContainsStringStartingWith(array: string[], prefixToFind: string)
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
if (enableHotModuleReplacement) {
// For this, we only support the key/value config format, not string or string[], since
Expand All @@ -46,10 +46,11 @@ function attachWebpackDevMiddleware(app: any, webpackConfig: webpack.Configurati
// Augment all entry points so they support HMR (unless they already do)
Object.getOwnPropertyNames(entryPoints).forEach(entryPointName => {
const webpackHotMiddlewareEntryPoint = 'webpack-hot-middleware/client';
const webpackHotMiddlewareOptions = `?path=` + encodeURIComponent(hmrEndpoint);
if (typeof entryPoints[entryPointName] === 'string') {
entryPoints[entryPointName] = [webpackHotMiddlewareEntryPoint, entryPoints[entryPointName]];
entryPoints[entryPointName] = [webpackHotMiddlewareEntryPoint + webpackHotMiddlewareOptions, entryPoints[entryPointName]];
} else if (!arrayContainsStringStartingWith(entryPoints[entryPointName], webpackHotMiddlewareEntryPoint)) {
entryPoints[entryPointName].unshift(webpackHotMiddlewareEntryPoint);
entryPoints[entryPointName].unshift(webpackHotMiddlewareEntryPoint + webpackHotMiddlewareOptions);
}
});

Expand Down Expand Up @@ -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)');
}
normalizedPublicPaths.push(removeTrailingSlash(publicPath));
attachWebpackDevMiddleware(app, webpackConfig, enableHotModuleReplacement, enableReactHotModuleReplacement);

const hmrEndpoint = `http://localhost:${listener.address().port}/__webpack_hmr`;
attachWebpackDevMiddleware(app, webpackConfig, enableHotModuleReplacement, enableReactHotModuleReplacement, hmrEndpoint);
}
});

Expand Down

0 comments on commit 93779a5

Please sign in to comment.