Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I got HMR working #6

Open
irperez opened this issue May 8, 2019 · 5 comments
Open

I got HMR working #6

irperez opened this issue May 8, 2019 · 5 comments
Labels
enhancement New feature or request Hacktoberfest

Comments

@irperez
Copy link

irperez commented May 8, 2019

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.

@danijelh
Copy link
Owner

danijelh commented May 8, 2019

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 danijelh added the enhancement New feature or request label May 8, 2019
@green16
Copy link

green16 commented Aug 14, 2019

@danijelh, hope this helps

@ToniKielo
Copy link

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,
    });

@livanov
Copy link

livanov commented Dec 2, 2019

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?

@danijelh
Copy link
Owner

danijelh commented Dec 3, 2019

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Hacktoberfest
Projects
None yet
Development

No branches or pull requests

5 participants