aspnetcore-vue-typescript-template icon indicating copy to clipboard operation
aspnetcore-vue-typescript-template copied to clipboard

I got HMR working

Open irperez opened this issue 5 years ago • 5 comments

Just a heads up.

I saw your previous #5 issue on HMR not working.

I added the following to the Startup.Configure method.

using Microsoft.AspNetCore.SpaServices.Webpack;

app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { HotModuleReplacement = true });

Once I do this, HMR works just fine. I don't have to hit F5 all I have to do is hit save.

irperez avatar May 08 '19 15:05 irperez

Gr8 news! I used this with Webpack 3 but after 4 was released it was broken.

Will try to implement it again and release the new version. I'll leave this issue open until then.

Thank you!

danijelh avatar May 08 '19 16:05 danijelh

@danijelh, hope this helps

green16 avatar Aug 14 '19 13:08 green16

This should make HMR work again with webpack 4.0+:

Node packages:

  • Add webpack-dev-middleware (latest)

webpack.config.js

  • Add nullcheck: if (argv && argv.mode === "production"); middleware leaves the argv null, thus previous if (argv.mode ...) crashes the build
  • return in export: mode: argv && argv.mode ? argv.mode : 'development'; if not returned, webpack defaults to production mode and doesn't use HMR

Startup.cs

  • Add inside "if (env.IsDevelopment())":

    app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { HotModuleReplacement = true, });

ToniKielo avatar Sep 16 '19 19:09 ToniKielo

Thanks for all your inputs, that got me going. However, I face an inconvenience that I'd like to fix - namely, the hot reload takes about 10-15 seconds on this rather empty project. How could I make this faster? I am not sure how to even start improving this time?

livanov avatar Dec 02 '19 09:12 livanov

@livanov That is not "normal" time of execution.

I have plans to add HMR and update the template to the .NET Core 3 but I am lacking the free time to do so.

You can use standard way of development. Watching for changes feature of the current template takes under a second to build the files. Downside is that, yes, you have to hit F5 manually.

danijelh avatar Dec 03 '19 19:12 danijelh