webpack-virtual-modules icon indicating copy to clipboard operation
webpack-virtual-modules copied to clipboard

Eliminate redundant rebuilds under watch mode in Webpack 5

Open andy0130tw opened this issue 2 years ago • 6 comments

What's the problem this PR addresses?

Try to eliminate extra rebuilds under watch mode, as issue #121 points out.

How did you fix it?

By making a proxy through WatchFileSystem, patching its aggregated listener with care and filter out virtual files. This way, no rebuild is triggered when the change only includes virtual files' false removals. For details, see https://github.com/sysgears/webpack-virtual-modules/issues/121#issuecomment-1000298229.

andy0130tw avatar Dec 23 '21 17:12 andy0130tw

There is a regression: test case "should invalidate bundle on dynamic module write" waits indefinitely.

I am uncertain about its intention. Maybe the test passed before is because of the extra rebuild behavior in Webpack 5. Should Webpack rebuild in this case?

andy0130tw avatar Dec 23 '21 17:12 andy0130tw

There is a regression: test case "should invalidate bundle on dynamic module write" waits indefinitely.

I am uncertain about its intention. Maybe the test passed before is because of the extra rebuild behavior in Webpack 5. Should Webpack rebuild in this case?

The intention of the test is to check that recompilation must happen after one of the source code files is changed on the file system. Maybe the test can be rewritten differently, but checking if recompilation really happens is certainly useful.

larixer avatar Dec 24 '21 10:12 larixer

There is a regression: test case "should invalidate bundle on dynamic module write" waits indefinitely. I am uncertain about its intention. Maybe the test passed before is because of the extra rebuild behavior in Webpack 5. Should Webpack rebuild in this case?

The intention of the test is to check that recompilation must happen after one of the source code files is changed on the file system. Maybe the test can be rewritten differently, but checking if recompilation really happens is certainly useful.

I understand it better now. For writeModule to work properly, the watch procedure should also be aware of changes on virtual files. In Webpack 5, seemingly only the file/folder watchers are responsible for triggering a rebuild process, as opposed to virtual files are never having actual watchers attached on them. I have to figure out a way to mock this, e.g., calling an arbitrary file watcher manually anyway.

By the way, I will update the code to run the patching function only in Webpack 5, making it compatible with v3 and v4.

andy0130tw avatar Dec 26 '21 12:12 andy0130tw

Is there any news on this ? I need this PR to be merge to fix a bug that is preventing me from using this plugin :(

Citriik avatar Feb 21 '22 11:02 Citriik

I need this feature. Please merged soon, thanks

hlerenow avatar Jun 09 '22 09:06 hlerenow

@hlerenow Until all the tests will pass the PR will not be merged.

larixer avatar Jun 09 '22 10:06 larixer

Closing, the PR breaks tests

larixer avatar Sep 17 '22 06:09 larixer