Skip to content

Commit 18e8b71

Browse files
In aspnet-webpack, allow webpack-hot-middleware/client to be added manually with options. Fixes aspnet#353
1 parent 6126c4d commit 18e8b71

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aspnet-webpack",
3-
"version": "1.0.16",
3+
"version": "1.0.17",
44
"description": "Helpers for using Webpack in ASP.NET Core projects. Works in conjunction with the Microsoft.AspNetCore.SpaServices NuGet package.",
55
"main": "index.js",
66
"scripts": {

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ interface DevServerOptions {
2626
ReactHotModuleReplacement: boolean;
2727
}
2828

29+
function arrayContainsStringStartingWith(array: string[], prefixToFind: string) {
30+
return array.some(item => item.substring(0, prefixToFind.length) === prefixToFind);
31+
}
32+
2933
function attachWebpackDevMiddleware(app: any, webpackConfig: webpack.Configuration, enableHotModuleReplacement: boolean, enableReactHotModuleReplacement: boolean) {
3034
// Build the final Webpack config based on supplied options
3135
if (enableHotModuleReplacement) {
@@ -39,12 +43,13 @@ function attachWebpackDevMiddleware(app: any, webpackConfig: webpack.Configurati
3943
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\' }")');
4044
}
4145

42-
// Augment all entry points so they support HMR
46+
// Augment all entry points so they support HMR (unless they already do)
4347
Object.getOwnPropertyNames(entryPoints).forEach(entryPointName => {
48+
const webpackHotMiddlewareEntryPoint = 'webpack-hot-middleware/client';
4449
if (typeof entryPoints[entryPointName] === 'string') {
45-
entryPoints[entryPointName] = ['webpack-hot-middleware/client', entryPoints[entryPointName]];
46-
} else {
47-
entryPoints[entryPointName].unshift('webpack-hot-middleware/client');
50+
entryPoints[entryPointName] = [webpackHotMiddlewareEntryPoint, entryPoints[entryPointName]];
51+
} else if (!arrayContainsStringStartingWith(entryPoints[entryPointName], webpackHotMiddlewareEntryPoint)) {
52+
entryPoints[entryPointName].unshift(webpackHotMiddlewareEntryPoint);
4853
}
4954
});
5055

0 commit comments

Comments
 (0)