-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delay loading a set of ids until all other files have been processed #4985
Comments
Maybe we could use the object form of hooks to mark hooks that should ignore that file operation limit? We would still need to think how this should work internally, but would this solve the issue? E.g. |
That could work, yes. I still feel we may be missing a simpler strategy (more thinking on Vite working with pre-bundling as default during build). If Rollup would add a specific option for this case, maybe it could already be an option that makes the whole scheme work without hacks. For example, during If not, we are forced to do one of the following:
|
Ah, that is actually a great idea. Some time ago I had the idea in my head to have something like "delayed dependencies", and/or a special hook that runs when the module loader is "idle" to be able to emit additional entries that rely on the current module graph. But this suggestion is actually simpler. So let me try to flesh this out a little more. So assume a plugin resolves to When the module loader is done resolving and loading everything it can and would run idle, it then picks the first delayed id. The next time it runs idle it loads the second delayed id and so on. What happens if some other import is resolved to an id that is marked as "delayed" but without
|
I think I would go with 2., if someone added
Another option would be that all the ids marked with A bit more complexity, just to put everything on the table. During build time, Vite could find worker entries. These are bundled in a separate rollup process when they are found (with a different set of plugins). But they share the same optimized deps processing and cache. Right now, we keep track of the ids that are being processed on all these rollup calls. If we get a |
Yes, I agree that would be even better. As I see it, it should be possible to implement something along these lines. If one from the Vite team wants to have a stab at this, I would be glad to support, otherwise it may need some time before I can look into this. |
Dropping a related link that this feature would help #4294. |
I think Some options: I'm leaning towards b. |
Yeah I think b is good enough. If they really need to wait for delayed modules to be loaded too, they can continue using the trick. The added benefit with this feature is that it won't be blocked on |
This need is also a big requirement to have a clean utility based CSS plugin. For now I've seen to option:
I went with the second option because the number of hacks to support esbuild that doesn't have a "generate chunks phase" was too high. Given that Tailwind 4 will provide a Vite plugin, this would really have a big impact if something to solve this was available in the Rollup API! |
I have implemented this locally for rollup using the |
Yeah the need is slightly different, the need to be able to know when all the load from a certain type is done. But this is tricky because it can easily introduce dead locks |
Feature Use Case
I don't know if this will require a new feature in Rollup, it may be that we aren't aware of a good way to implement this feature in Vite.
We have an experimental feature to pre-bundle dependencies during build time using esbuild. We do this during dev because of CJS interop (we don't use rollup plugin CommonJS) and we want to reduce the number of files we sent to the browser (one file for all of lodash). During build, pre-bundling would allow us to reduce the difference between dev and build and hopefully speed up build times because deps pre-bundling is cached. It could also potentially help us with memory consumption.
To be able to implement prebundling, we first need a complete list of all entry points to dependencies that should be prebundled. Then we do a single esbuild bundling with all these entry points. To get the list, we need to wait for every file that isn't an entry point to be optimized to be processed. We have a scheme in place where we register all non-optimized ids during
resolveId
and then callthis.load()
on them. On theload
hook we wait for all these load events to finish, then we optimize with esbuild, and finally resolve the loading of all the optimized deps.The issue is that each awaited optimized dep will count towards
maxParallelFileOps
, so now users need to bump this option for the scheme to work.We tried alternative options, like registering during
resolveId
(using a timeInterval to avoid an early exit), and then marking the id as done during transform withpost
order. The effect is the same. Here is another option from @sun0day, but I feel we are missing a simpler alternative.Feature Proposal
Is there a way to avoid starting loading of optimized deps so they don't count towards
maxParallelFileOps
? Maybe a new feature is needed here or there is something we are currently missing. Sorry for the semi-support disguised as a feature request in that case.The text was updated successfully, but these errors were encountered: