Skip to content
This repository was archived by the owner on Dec 20, 2018. It is now read-only.
This repository was archived by the owner on Dec 20, 2018. It is now read-only.

Angular 6's dev server with HMR #734

Closed
@dubeg

Description

@dubeg

I have trouble setting up UseProxyToSpaDevelopmentServer with the angular dev server with HMR set up. It seemed to work before updating the Angular app to version 6.2.1. Before, it was version 5.x.x, I think.

I followed the instructions from the angular-cli's document, however I met some problems when trying it out.

Here's what I ran:

  • ng serve --configuration hmr in one terminal, listening to http://localhost:4200.
  • dotnet run in another terminal, listening to http://localhost:57084.

When visiting localhost:57084 in a browser, the Angular app wouldn't load, and I'd find the message HMR is not enabled for webpack-dev-server! in the console. However, when visiting localhost:4200, the Angular app would load and HMR would be enabled.

After a bit of searching, I found that ng serve builds and keeps its output in memory, while the dotnet app uses the files in /dist/ (the call to UseSpaStaticFiles in startup.cs is responsible for this, I think).

So my current workaround is to remove the call to UseSpaStaticFiles when I call UseProxyToSpaDevelopmentServer. The angular app's files seem to be correctly retrieved from the dev server, instead of being retrieved from the /dist/ folder. However, I'm wondering if this is the correct way to make it work, since it isn't instructed here.

Out of curiosity, I tried to build with ng build --configuration hmr before running the angular dev server, just to see if it worked. It didn't. In /dist/main.js, I found this:

...
if (_environments_environment__WEBPACK_IMPORTED_MODULE_3__["environment"].hmr) {
    if (false) {}
    else {
        console.error('HMR is not enabled for webpack-dev-server!');
        console.log('Are you using the --hmr flag for ng serve?');
    }
}
else {
    bootstrap();
}
...

So it seems that the hmr-related code is being removed on ng build --configuration hmr, but not on ng serve --configuration hmr.

One last note: I noticed that you could setup HMR using SpaServices, but this is to be used with UseAngularCliServer, correct?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions