You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: extend defineConfig to support lazy plugin loading via factory functions
The `plugins` field in `defineConfig` now accepts factory functions
(`() => PluginOption[]` or `async () => Promise<PluginOption[]>`)
in addition to the standard `PluginOption[]` array.
The factory is only called for vite commands (dev, build, test, preview)
and skipped for non-vite commands (lint, fmt, check, etc.), avoiding
unnecessary plugin loading overhead. When VP_COMMAND is unset (e.g.,
running vitest directly or via VS Code extension), plugins load by default.
VP_COMMAND is set automatically by `vp` in bin.ts and injected into
child process envs by the Rust resolver for synthesized subcommands.
Refs vitejs/vite#22085
Copy file name to clipboardExpand all lines: docs/guide/troubleshooting.md
+31Lines changed: 31 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -89,6 +89,37 @@ export default defineConfig({
89
89
});
90
90
```
91
91
92
+
## Slow config loading caused by heavy plugins
93
+
94
+
When `vite.config.ts` imports heavy plugins at the top level, every `import` is evaluated eagerly, even for commands like `vp lint` or `vp fmt` that don't need those plugins. This can make config loading noticeably slow.
95
+
96
+
Pass a factory function to `plugins` in `defineConfig` to defer plugin loading. The factory is only called for commands that need plugins (`dev`, `build`, `test`, `preview`), and skipped for everything else:
97
+
98
+
```ts
99
+
import { defineConfig } from'vite-plus';
100
+
101
+
exportdefaultdefineConfig({
102
+
plugins: () => [myPlugin()],
103
+
});
104
+
```
105
+
106
+
For heavy plugins that should be lazily imported, combine with dynamic `import()`:
The plugins factory requires `defineConfig` from `vite-plus`, not from `vite`. Vite's native `defineConfig` does not support factory functions for the `plugins` field.
0 commit comments