feat: extend defineConfig to support lazy plugin loading via factory functions#1215
feat: extend defineConfig to support lazy plugin loading via factory functions#1215
Conversation
✅ Deploy Preview for viteplus-preview canceled.
|
How to use the Graphite Merge QueueAdd the label auto-merge to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
5adc3fd to
49d17df
Compare
leaysgur
left a comment
There was a problem hiding this comment.
I have no objection to recommending this method as a current workaround. 👌🏻
(However, I cannot judge whether this is the best approach, as I do not know the background behind why this lazy was introduced.)
|
I'm really not a fan of the lazy attribute and I don't think we should recommend it. It would be better to make the plugins field either an array or a function that returns |
49d17df to
b3cb2f5
Compare
This needs to be resolved on the Vite side. I think Vite+ should not change the meaning of fields defined by Vite. @sapphi-red |
b3cb2f5 to
8936d0c
Compare
|
Upstream issue created here: vitejs/vite#22085 |
8936d0c to
71d3659
Compare
|
I don't really follow, why do we need to add a new function to wrap plugins instead of redefining the plugin type from |
That only works if we'd "guarantee" there are no plugins that can influence the behavior of |
|
For now, that's the expectation, yes. |
|
I think then we can also wrap the whole function (as long there is no type mismatch or we alter the allowed types of |
7a6bc52 to
91d5fdf
Compare
This comment was marked as outdated.
This comment was marked as outdated.
4f0cf8a to
3c27538
Compare
3c27538 to
63140ee
Compare
This comment was marked as duplicate.
This comment was marked as duplicate.
63140ee to
a1c78a7
Compare
This comment was marked as outdated.
This comment was marked as outdated.
cpojer
left a comment
There was a problem hiding this comment.
It's beautiful. From a UX perspective, I love it. I don't know if there are any remaining concerns from the Vite side, cc @sapphi-red if you don't mind signing off on this 🙇♂️
e9d0689 to
db118db
Compare
…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
db118db to
ca6266c
Compare
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit ca6266c. Configure here.

Summary
Extend
defineConfigso thepluginsfield accepts factory functions in addition to the standardPluginOption[]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.Refs vitejs/vite#22085
Usage
How it works
bin.tssetsVP_COMMANDenv var from the CLI command argumentdefineConfigchecks ifpluginsis a function; if so, only calls it whenVP_COMMANDis a vite commandasyncFlattenresolves it during plugin pipelineTest plan
vp checkpasses (format + lint)🤖 Generated with Claude Code
Note
Medium Risk
Changes how
vite.config.tsplugins are resolved based on the runningvpcommand, which could affect plugin execution order/availability across build/test/dev vs lint/fmt/check paths. AddsVP_COMMANDenv injection in both JS and Rust CLI flows, so regressions would show up as incorrect plugin loading in synthesized commands (e.g.vp run).Overview
Adds lazy plugin loading to
vite-plusdefineConfigby allowingpluginsto be a sync/async factory function; the factory is executed only for Vite commands (dev/build/test/preview) and skipped for non-Vite commands to reduce config-load overhead.The CLI now sets/injects
VP_COMMAND(JSbin.ts, and Rust resolver for synthesized subcommands) so factory decisions remain correct even when commands are executed viavp run. Includes expanded unit coverage, new snapshot fixtures validating sync/async factories (including VitestconfigureVitest) and that plugins are not loaded duringvp lint, plus a small Windows snapshot-stabilization tweak and updated troubleshooting docs.Reviewed by Cursor Bugbot for commit ca6266c. Configure here.