aurelia / loader-webpack

An implementation of Aurelia's loader interface to enable webpack.
MIT License
26 stars 9 forks source link

Code split module doesn't get updated in HMR mode #39

Closed jussimattila closed 6 years ago

jussimattila commented 6 years ago

I'm submitting a bug report

Please tell us about your environment:

Current behavior: Hot module replacement of TypeScript source code doesn't work with Aurelia modules that have been split to a separate file using PLATFORM.modulesName(...) overload with chunk parameter, e.g. PLATFORM.moduleName(/* module */ '../counter/counter', /* chunk */ 'counter'). Removing the second argument ('counter') allows HMR to work normally.

To reproduce:

Create a new aurelia application using Microsoft's SpaTemplates: dotnet new aurelia. You may need to install the templates first using dotnet new -i "Microsoft.AspNetCore.SpaTemplates::*". After the project is created, npm install dependencies.

Make one change in app.ts, modify line 20 to: moduleId: PLATFORM.moduleName('../counter/counter', 'counter'),, i.e. add the chunk name argument. Run the application with HMR. Load counter page and click on the increment button to see it add 1 to counter. Now change code in counter.ts from this.currentCount += 1; to this.currentCount += 10; and save changes. HMR kicks in and does something, but falls short on actually updating the application. Click on the increment button and see that it is still adding only 1, not 10.

Changes in TypeScript source code should be reflected in the running application through HMR. Change to the increment code should affect the result from clicking on the increment button.

I wan't to develop modules using code splitting and with HMR enabled.

I've not contributed to Aurelia, but here's a PR on my fork for the change that appears to fix this issue: https://github.com/jussimattila/loader-webpack/pull/1

Alexander-Taran commented 6 years ago

If you will consider providing a PR to this repo.. There are some guidelines on commit messages. Which help to build change log.

jussimattila commented 6 years ago

Sure, I didn't have time for it immediately, but if that is desired, I'll have a look at contribution guidelines and prepare a PR during this week.

Alexander-Taran commented 6 years ago

PR waiting. @niieani & @EisenbergEffect who can review it?

niieani commented 6 years ago

Not sure what was the reason I didn't handle async modules, but if it fixes the problem, then that's great, since it shouldn't cause any issues. Thanks!