In aspnet-webpack HMR, don't rely on assumption that entry point is called 'main'. Fixes #289.

This commit is contained in:
SteveSandersonMS
2016-09-09 13:21:31 +01:00
parent 605090e909
commit bc2de2ad59
2 changed files with 20 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
{
"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.",
"main": "index.js",
"scripts": {

View File

@@ -43,12 +43,26 @@ export function createWebpackDevServer(callback: CreateDevServerCallback, option
const listener = app.listen(suggestedHMRPortOrZero, () => {
// Build the final Webpack config based on supplied options
if (enableHotModuleReplacement) {
// TODO: Stop assuming there's an entry point called 'main'
if (typeof webpackConfig.entry['main'] === 'string') {
webpackConfig.entry['main'] = ['webpack-hot-middleware/client', webpackConfig.entry['main']];
} else {
webpackConfig.entry['main'].unshift('webpack-hot-middleware/client');
// For this, we only support the key/value config format, not string or string[], since
// those ones don't clearly indicate what the resulting bundle name will be
const entryPoints = webpackConfig.entry;
const isObjectStyleConfig = entryPoints
&& 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(
new webpack.HotModuleReplacementPlugin()
);