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:
- Do nothing, and tell users to fix their plugins.
- Keep
lazy and ask Vite to ship this feature as well.
- 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>>.
- Allow fields to be specified as getters, which can be lazy.
- 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
Description
We need to ensure that
vite.config.tsstays 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 undocumentedlazyflag that can be used to make plugins lazy, but we are not happy with the solution. There are multiple options:lazyand ask Vite to ship this feature as well.pluginsoptionally lazy. Instead ofplugins: Array<Plugin>, it could be typed asplugins: Array<Plugin> | () => Promise<Array<Plugin>>.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