JoviDeCroock / webpack-module-nomodule-plugin

Easily implement a module nomodule index.html
82 stars 6 forks source link

Use a promise to ensure that iteration 2 won't run before the assets are emitted from iteration 1 #31

Closed thecontrarycat closed 3 years ago

thecontrarycat commented 3 years ago

From using this plugin with a lot of different webpack 5 configurations I have discovered that it is possible for iteration 2 to begin processing prior to iteration 1 being completed.

This causes issues with RealContentHash because iteration 2 will take the old hashes from the .json file (this file is updated during the emit phase).

To fix this we can use a Promise to ensure that iteration 2 doesn't begin processing until iteration 1 has been emitted. We hook compiler.hooks.afterEmit() to resolve the Promise.

thecontrarycat commented 3 years ago

After further testing, it appears that the race condition problem only affects Node 12.x and not Node 14.x, so I'm going to do a further commit to make this synchronisation optional.

thecontrarycat commented 3 years ago

I'm going to close this because I can't reproduce the race condition on my work laptop. It was only happening on one computer, and only when using Node 12. Very strange.