[Bug] virtual module trigger extra compilation in webpack 5
See original GitHub issue- I’d be willing to submit the fix
Describe the bug
Using the latest webpack 5 and the latest webpack-virtual-modules. I notice that webpack is logging out 2 compilation in watch mode.
To Reproduce
Run webpack --watch
to reproduce using this brranch: https://github.com/michenly/webpack-5-demo/tree/webpack-virtual-modules-error
Minimally, use webpack-virtual-modules (I did this in both in a plugin with .apply
and in webpack config’s plugin directly with the same result)
new VirtualModulesPlugin({'test.js': `export default 'test123'`})
Log out compilation message by tapping into compiler.hooks.compile
and see two compilation message as soon as webpack --watch
is run
Screenshots
Environment if relevant (please complete the following information):
- OS: OSX 11.15.1
- Node version: v12.14.0
- Mochapack version: ?
- Webpack version: 5.50.0
- webpack-virtual-modules version: 0.4.3
Additional context
I also log out complier.removedFiles
in compiler.hooks.watchRun
, notice how the virtual module is listed as files that was removed.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:8
- Comments:5 (2 by maintainers)
Top GitHub Comments
@larixer Sure. I have opened a PR.
Update: I have worked out a more robust,
Proxy
-based solution that treats the originalWatchFileSystem
as an abstract object. Should be more resilient to breaking changes in Webpack and Watchpack.Code: https://github.com/andy0130tw/webpack-virtual-modules/blob/24d823f3133da9f397224cdfedd39be341546b21/src/wfs.ts