WebpackDevMiddleware in ASP.NET Core app in Azure Service Fabric

Viewed 587

I am trying to use WebpackDevMiddleware with HotModuleReplacement in an ASP.NET Core app. I followed the following guide: https://docs.microsoft.com/en-us/aspnet/core/client-side/spa-services in setting up webpack to work with ASP.NET.

When I deploy my ASP.NET Core app via Service Fabric, the following error is thrown:

Call to Node module failed with error: Webpack dev middleware failed because of an error while loading 'aspnet-webpack'....

I noticed that inside my wwwroot/ folder, I have no node_modules, dependencies, etc... and so this error seems to make sense. The ASP.NET core app does not seem to have access to the aspnet-webpack node module. Additionally, in other projects' wwwroot folders there appears to be a dependencies folder visible in Visual Studio, while in mine there is no such folder.

I'm wondering how I can give the ASP.NET core app access to the modules it needs?

1 Answers

It seems that ServiceFabric does not support Hot Module Replacement at this time.

To get around this I added the following:

#if DEBUG
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
{
    HotModuleReplacement = true
});
#endif

So that you only use HMR when in debug mode and when you publish to local/production cluster HMR is not used.

Related