Skip to content

Delay loading a set of ids until all other files have been processed #4985

@patak-cat

Description

@patak-cat

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 call this.load() on them. On the load 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 with post 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions