aspnetcore-vue-typescript-template
aspnetcore-vue-typescript-template copied to clipboard
I got HMR working
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.
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, hope this helps
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, });
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 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.