Comments (5)
Took several days to bisect the problem. The problem lies in the fact that WatchFileSystem
will scan the filesystem after a compilation has finished, and if it finds any differences, it triggers a rebuild. This scan obviously does not go through the cached input file system, so it reports that the virtual modules "missing in initial scan" (sample). It boils down to the following steps:
Watchpack
goes through all "watchers" it keeps (1, 2), in our case, this eventually calls_onRemove
method on virtual files.- Collected changes are buffered and emitted with an "aggregated" event.
- The key is that watchFileSystem always calls the callback upon receiving the event, effectively triggers another watch cycle (with virtual modules purged from inputFileSystem so the virtual module plugin adds it back).
My idea to deal with this is to steal the watchFileSystem and roll a new one that filters out virtual files before proceeding. If none of the removals come from actual files, then we can safely ignore this event.
This involves precisely mimicing what Watchpack does (which slightly varies across versions of Webpack). The drawback is that we definitely need separate implementations for Webpack 3, 4, and 5, and the way is not future-proof.
Forgive me that writing clean TS is time-consuming for me. Moreover, under Webpack 5.64.1, when logging things down, I see some nonsense removals (like node_modules/babel-loader.js/package.json
) that still trigger the rebuilds 2~3 times, possibly related to buggy cache, but I am running out of time budgets on studying this further. I will be grateful if someone can turn this idea into a PR.
Update: Did some quick tests, my fork works for me 5.60~5.64.0, and 5.64.1 with --no-cache
.
from webpack-virtual-modules.
Update: I have worked out a more robust, Proxy
-based solution that treats the original WatchFileSystem
as an abstract object. Should be more resilient to breaking changes in Webpack and Watchpack.
from webpack-virtual-modules.
@larixer Sure. I have opened a PR.
from webpack-virtual-modules.
@andy0130tw Awesome, do you still have no bandwidth for the pull request?
from webpack-virtual-modules.
Closing the issue as stale, please retest on latest webpack-virtual-modules
and reopen with reproduction steps if the issue still exists.
from webpack-virtual-modules.
Related Issues (20)
- [Bug] Plugin causes console noise when used alongside debug.js HOT 2
- [Feature] Support removeModule API HOT 6
- [Bug] Uppercase driver letter in windows
- Incorrectly used fileWatcher, that causing writeModule not trigger recompile with webpack-dev-server HOT 1
- [Feature] GetModule/ReadModule API HOT 2
- [Bug] Using React/JSX with `webpack-virtual-modules` gives error even when `@babel/preset-react` is used HOT 1
- [Bug] HOT 1
- [Question] - Is it possible generate new virtual modules based on file-system changes? HOT 1
- [Bug] ModuleNotFoundError happened ,when I compile two project in the same progress HOT 3
- [Bug] Local version of webpack-virtual-modules in next-with-linaria HOT 3
- [Question] Next.js compatibility
- [Bug] Multiple config and broken invalidation right from the start HOT 10
- [Feature] Custom URI scheme
- What are some real usecases of this plugin? HOT 1
- [Bug] Infinite loop on the webpack 5 example HOT 8
- [Bug] Question: Trigger webpack rebuild HOT 7
- [Feature] Expose types HOT 1
- [Bug] Stale virtual module contents upon ".writeModule" HOT 6
- [Bug] Compatibility with AngularCompilerPlugin HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webpack-virtual-modules.