NativeScript / worker-loader

36 stars 20 forks source link

HMR doesn't work in projects that use Plugins that use workers #41

Closed shiv19 closed 4 years ago

shiv19 commented 5 years ago

https://github.com/EddyVerbruggen/nativescript-particle/issues/7 NativeScript6 Particle Plugin HMR issue.zip

HMR doesn't work when using nativescript-particle plugin.

This problem did not exist in older versions of dev-webpack

DimitarTachev commented 5 years ago

Hi @shiv19,

Thanks for reporting that!

In nativescript@5.4 we had an issue with the updates of static resources during HMR LiveSync. The CLI was always refrehing the application on HMR change and files like images, fonts and databases were not properly updated with HMR sync. In this way, the users were forced to stop the command and re-run it when they need to update such file.

In order to fix that, starting from nativescript@6.0.0 we are restarting the application when the Webpack process emits a file different than a hot update. In this way, the updates of static resources that are included in the app through the CopyWebpackPlugin are causing an app restart and the app is properly updated.

The issue with apps using the Worker plugin is caused by the following behavior: 1) The Worker plugin is always emitting an additional file (__worker-chunks.json) in the Webpack compilation. This is not a hot update file and the CLI is restarting the app in order to apply it. 2) The Worker loader is creating a child Webpack process for each worker file and these Webpack processes are emitting [hash].worker.js files. These files are also triggering an app restart as they are not hot updates.

In other words, the Worker plugin and loader should stop emitting these files on each change and we will move this issue in the Worker loader repository. Unfortunately, the above-mentioned point (2) does not have an easy fix and most probably it will be a known limitation for nativescript@6.0.0 till we release a better version of the Worker plugin.

AtoianAvetik commented 4 years ago

Hi @DimitarTachev, What you can say about this small plugin https://github.com/TrigenSoftware/hmr-filter-webpack-plugin, can it help as a workaround? I tried to use it but nothing happens.

DimitarTachev commented 4 years ago

Hi @AtoianAvetik,

Thanks for your help!

Unfortunately, this plugin won't change the problematic behavior as the Worker chunks are already excluded from the HMR updates (they are generated by another Webpack process). We need the opposite logic, the Worker chunks should be included in the hot updates in order to avoid the app restart. As I've already mentioned, this issue should be handled in the nativescript-worker-plugin itself, as it's spawning a child Webpack process with a custom config.

AtoianAvetik commented 4 years ago

@DimitarTachev, thanks for such a quick reply. Then we will wait for other news from you. Thanks!

KristianDD commented 4 years ago

Acceptance criteria Initial setup:

  1. Download repository
  2. In demo-angular - npm i --save-exact nativescript-worker-loader@next