mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 01:58:29 +00:00
In aspnet-webpack, allow webpack-hot-middleware/client to be added manually with options. Fixes #353
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "aspnet-webpack",
|
"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.",
|
"description": "Helpers for using Webpack in ASP.NET Core projects. Works in conjunction with the Microsoft.AspNetCore.SpaServices NuGet package.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ interface DevServerOptions {
|
|||||||
ReactHotModuleReplacement: boolean;
|
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) {
|
function attachWebpackDevMiddleware(app: any, webpackConfig: webpack.Configuration, enableHotModuleReplacement: boolean, enableReactHotModuleReplacement: boolean) {
|
||||||
// Build the final Webpack config based on supplied options
|
// Build the final Webpack config based on supplied options
|
||||||
if (enableHotModuleReplacement) {
|
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\' }")');
|
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 => {
|
Object.getOwnPropertyNames(entryPoints).forEach(entryPointName => {
|
||||||
|
const webpackHotMiddlewareEntryPoint = 'webpack-hot-middleware/client';
|
||||||
if (typeof entryPoints[entryPointName] === 'string') {
|
if (typeof entryPoints[entryPointName] === 'string') {
|
||||||
entryPoints[entryPointName] = ['webpack-hot-middleware/client', entryPoints[entryPointName]];
|
entryPoints[entryPointName] = [webpackHotMiddlewareEntryPoint, entryPoints[entryPointName]];
|
||||||
} else {
|
} else if (!arrayContainsStringStartingWith(entryPoints[entryPointName], webpackHotMiddlewareEntryPoint)) {
|
||||||
entryPoints[entryPointName].unshift('webpack-hot-middleware/client');
|
entryPoints[entryPointName].unshift(webpackHotMiddlewareEntryPoint);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user