If you're using Vue for the front end and .Net Core 3.1 for the backend this should help you. I wasn't able to get HMR working from IIS but if you run IIS to start up your backend and then run the Vue part only on a different port you can proxy all calls to your backend and have the app fully functional with HMR that way. So in startup.cs you're going to want to add
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
if (env.IsDevelopment())
{
endpoints.MapToVueCliProxy(
"{*path}",
new SpaOptions { SourcePath = "ClientApp" },
npmScript: "serve",
port: 8000,
regex: "Compiled successfully");
}
// Add MapRazorPages if the app uses Razor Pages. Since Endpoint Routing includes support for many frameworks, adding Razor Pages is now opt -in.
endpoints.MapRazorPages();
});
app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
});
and include these packages at the top as well
using Microsoft.AspNetCore.SpaServices;
using VueCliMiddleware;
using Microsoft.AspNetCore.SpaServices.Webpack;
Then create a vue.config.js in the root of your ClientApp folder and in there put
module.exports = {
devServer: {
proxy: "https://localhost:44354",
host: "localhost",
}
}
Of course the value for proxy is going to be the URL that comes up when you start IIS.
So now if you start your IIS and then in a terminal from your client app run npm run serve your Client app will now be able to proxy calls to your backend and you will have HMR up and working. For most people this will work fine but one problem I ran into is errors being thrown from each end and cookies not being set this way and a few other problems. The problem all revolves around your IIS being ran on HTTPS and your webpack dev server being ran on HTTP. So the way I solved this is to add another script to my package.json like so
"dev": "vue-cli-service serve --https --port 8082"
So now when you start your IIS it will run the command of npm run serve which will provide no https, which is what you want. Then from your ClientApp folder run npm run dev which will provide you with HTTPS on your front end. But there is one more problem now, when you open localhost from your front end chrome will throw an error saying this site is not safe and then you have to click advanced and choose to proceed. So errors will still be thrown and cookies won't be set. What I did was go into VS code and created a new file called Localhost.cer. Then in your browser at the top left where that error is being thrown about not being secure(it's in red) click on that then go to details. Then I think its save files or import files or something like that click on that then the certificate wizard should pop up and your going to want to save that file as a whole to the Localhost.cer that you previously created. Then go to google settings up at the top search for certificates. Privacy and security should pop up then click more. Then click manage certificates, then click trusted root certification authorities and import that Localhost.cer file up there. That will get rid of the error that pops up.