In aspnet-webpack, allow webpack-hot-middleware/client to be added manually with options. Fixes #353

This commit is contained in:
SteveSandersonMS
2016-10-04 11:36:10 +01:00
parent 6126c4d480
commit 18e8b7101c
2 changed files with 10 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "aspnet-webpack",
"version": "1.0.16",
"version": "1.0.17",
"description": "Helpers for using Webpack in ASP.NET Core projects. Works in conjunction with the Microsoft.AspNetCore.SpaServices NuGet package.",
"main": "index.js",
"scripts": {

View File

@@ -26,6 +26,10 @@ interface DevServerOptions {
ReactHotModuleReplacement: boolean;
}
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) {
// Build the final Webpack config based on supplied options
if (enableHotModuleReplacement) {
@@ -39,12 +43,13 @@ function attachWebpackDevMiddleware(app: any, webpackConfig: webpack.Configurati
throw new Error('To use HotModuleReplacement, your webpack config must specify an \'entry\' value as a key-value object (e.g., "entry: { main: \'ClientApp/boot-client.ts\' }")');
}
// Augment all entry points so they support HMR
// Augment all entry points so they support HMR (unless they already do)
Object.getOwnPropertyNames(entryPoints).forEach(entryPointName => {
const webpackHotMiddlewareEntryPoint = 'webpack-hot-middleware/client';
if (typeof entryPoints[entryPointName] === 'string') {
entryPoints[entryPointName] = ['webpack-hot-middleware/client', entryPoints[entryPointName]];
} else {
entryPoints[entryPointName].unshift('webpack-hot-middleware/client');
entryPoints[entryPointName] = [webpackHotMiddlewareEntryPoint, entryPoints[entryPointName]];
} else if (!arrayContainsStringStartingWith(entryPoints[entryPointName], webpackHotMiddlewareEntryPoint)) {
entryPoints[entryPointName].unshift(webpackHotMiddlewareEntryPoint);
}
});