mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 01:58:29 +00:00
In aspnet-webpack HMR, don't rely on assumption that entry point is called 'main'. Fixes #289.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "aspnet-webpack",
|
"name": "aspnet-webpack",
|
||||||
"version": "1.0.10",
|
"version": "1.0.11",
|
||||||
"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": {
|
||||||
|
|||||||
@@ -43,12 +43,26 @@ export function createWebpackDevServer(callback: CreateDevServerCallback, option
|
|||||||
const listener = app.listen(suggestedHMRPortOrZero, () => {
|
const listener = app.listen(suggestedHMRPortOrZero, () => {
|
||||||
// Build the final Webpack config based on supplied options
|
// Build the final Webpack config based on supplied options
|
||||||
if (enableHotModuleReplacement) {
|
if (enableHotModuleReplacement) {
|
||||||
// TODO: Stop assuming there's an entry point called 'main'
|
// For this, we only support the key/value config format, not string or string[], since
|
||||||
if (typeof webpackConfig.entry['main'] === 'string') {
|
// those ones don't clearly indicate what the resulting bundle name will be
|
||||||
webpackConfig.entry['main'] = ['webpack-hot-middleware/client', webpackConfig.entry['main']];
|
const entryPoints = webpackConfig.entry;
|
||||||
} else {
|
const isObjectStyleConfig = entryPoints
|
||||||
webpackConfig.entry['main'].unshift('webpack-hot-middleware/client');
|
&& typeof entryPoints === 'object'
|
||||||
|
&& !(entryPoints instanceof Array);
|
||||||
|
if (!isObjectStyleConfig) {
|
||||||
|
callback('To use HotModuleReplacement, your webpack config must specify an \'entry\' value as a key-value object (e.g., "entry: { main: \'ClientApp/boot-client.ts\' }")', null);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Augment all entry points so they support HMR
|
||||||
|
Object.getOwnPropertyNames(entryPoints).forEach(entryPointName => {
|
||||||
|
if (typeof entryPoints[entryPointName] === 'string') {
|
||||||
|
entryPoints[entryPointName] = ['webpack-hot-middleware/client', entryPoints[entryPointName]];
|
||||||
|
} else {
|
||||||
|
entryPoints[entryPointName].unshift('webpack-hot-middleware/client');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
webpackConfig.plugins.push(
|
webpackConfig.plugins.push(
|
||||||
new webpack.HotModuleReplacementPlugin()
|
new webpack.HotModuleReplacementPlugin()
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user