voidzero-dev / voidzero-dev/vite-plus

defineConfig always injects vite-plus:vitest-resolver into vp build / vp dev even when Vitest isn't used

Ouverte
#2,307 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
pending triage
Langage dominant
Rust
Étoiles
5.8k
Forks
262
Merge moyen
23 h 41 min
PR mergées (30 j)
138

Description

### Describe the bug

`defineConfig` from `vite-plus` always prepends Vitest-only plugins into every Vite config, including for `vp build` / `vp dev`:

- `vite-plus:vitest-resolver`
- `vite-plus:auto-inline-matcher`
- `vite-plus:coverage-version-guard`

Projects that use Vite+ for toolchain (`fmt` / `lint` / `build`) but run tests with another runner (e.g. Bun's `bun:test`) still pay for these plugins on every production build.

Rolldown/Vite plugin timings report:

```text
[PLUGIN_TIMINGS] Your build spent significant time in plugins. Here is a breakdown:
- vite-plus:vitest-resolver (87%)
```

The resolver is an `enforce: "pre"` `resolveId` hook, so it runs on every module resolve. It early-returns for non-`vitest` / `@vitest/*` ids, but with a large graph that still dominates **plugin** time.

There is no documented opt-out. `lazyPlugins` only gates *user* plugins during config-metadata loads; it does not skip these injected plugins on `build`/`dev`. `vite-plus/prefer-vite-plus-imports` also pushes app configs to import `defineConfig` from `vite-plus` rather than `vite`, so switching away isn't a clean escape hatch.

### Reproduction

1. Use `import { defineConfig } from "vite-plus"` in an app `vite.config.ts`
2. Do **not** configure or run `vp test` / Vitest
3. Run `vp build` (with plugin timings enabled)
4. Observe `vite-plus:vitest-resolver` near the top of `[PLUGIN_TIMINGS]`

### Expected

Vitest helper plugins should only be injected when running tests (`vp test` / Vitest), or there should be an explicit opt-out for projects that don't use Vitest.

### System Info

- `vite-plus`: `0.2.5`
- Tests: Bun (`bun:test`), not Vitest
- Apps build via `vp build`

### Suggested fix

- Gate injection on test command / presence of `test` config, **or**
- Add a config flag such as `test: false` / `vitest: false` to skip injection, **or**
- Document a supported way to opt out without fighting `prefer-vite-plus-imports`

### Related

- Implementation that introduced/patched the resolver: https://github.com/voidzero-dev/vite-plus/pull/356
- Auto-inline matcher: https://github.com/voidzero-dev/vite-plus/pull/1113
- `lazyPlugins` (user plugins only): https://github.com/voidzero-dev/vite-plus/pull/1215

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Reproduisez le problème avec un vite.config.ts qui importe defineConfig depuis vite-plus et exécutez vp build avec les timings des plugins activés. Lisez les changements du resolver et de l’auto-inline matcher dans les PRs 356 et 1113, puis suivez la manière dont vp build, vp dev et vp test les injectent ; le travail est terminé lorsque les commandes autres que les tests n’entraînent plus le chargement de plugins propres à Vitest ou qu’une option d’exclusion documentée existe.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
bun, typescript
Domaine
build-system, tooling
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
Calme
Clarté
Plutôt claire
Accessibilité débutants
52/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.