Skip to content

[Vite+] Ensure that vite.config.ts stays fast for Vite+ use-cases. #22085

@cpojer

Description

@cpojer

Description

We need to ensure that vite.config.ts stays fast for a variety of use-cases in Vite+, beyond just Vite on its own. We have noticed that plugin loading can take several seconds due to slow third-party plugin initialization code. While that should be fixed in those plugins directly and they should be made lazy, we cannot control all environments. Config loading should stay fast by default regardless of third-party plugin usage.

See https://qiita.com/hal_mkiin/items/95e619aa7157023a5210 for a user story.

Suggested solution

Vite+ specifically adds configuration for formatting, linting, tasks to vite.config.ts. Vite+ has an undocumented lazy flag that can be used to make plugins lazy, but we are not happy with the solution. There are multiple options:

  1. Do nothing, and tell users to fix their plugins.
  2. Keep lazy and ask Vite to ship this feature as well.
  3. Make potentially slow config options like plugins optionally lazy. Instead of plugins: Array<Plugin>, it could be typed as plugins: Array<Plugin> | () => Promise<Array<Plugin>>.
  4. Allow fields to be specified as getters, which can be lazy.
  5. When using Vite+, allow every field in the config to be potentially lazy.

Personally, I think 3. is the sweet spot for now. It unblocks the direct issue without making the config API significantly worse. We are considering printing a warning when config loads are slow in Vite+, so if Vite implements a lazy-loading mechanism we can steer users towards any solution that we choose.

cc @fengmk2 @leaysgur @sapphi-red

Alternative

No response

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-downstream-blockerBlocking the downstream ecosystem to work properly (priority)

    Projects

    Status

    Discussing

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions