Skip to content

Conversation

@patak-dev
Copy link
Member

Description

After #20170, there isn't an easy way to get the resolved plugins for each environment before the post-config stage kicks in.

This PR introduces an experimental environmentConfigResolved hook that is called for each environment. The environment.config.plugins for each environment get called, meaning that plugins returned in applyToEnvironment would also participate (and that if a plugin was removed for an environment, their environmentConfigResolved will not be called for that environment).

@patak-dev patak-dev added p2-nice-to-have Not breaking anything but nice to have (priority) feat: environment API Vite Environment API labels Jun 6, 2025
@danielroe
Copy link
Contributor

danielroe commented Sep 18, 2025

I would find this useful for Nuxt. We currently 'grab' the resolved nuxt client side configuration for use in our vitest environment (and storybook does the same). In migrating to the vite environment API, we're missing a similar configResolved-ish hook that would give us access to all the plugins added/applied in applyToEnvironment.

Comment on lines +273 to +275
environmentConfigResolved?: (
environment: PartialEnvironment,
) => boolean | Promise<boolean> | PluginOption
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type signature mismatch: The hook definition allows returning boolean | Promise<boolean> | PluginOption, but the implementation in config.ts (lines 2196-2198) calls the handler without handling return values. This creates a semantic mismatch where plugins might expect their return values to be processed (especially PluginOption which suggests plugin registration), but the implementation ignores all return values. Either change the return type to void | Promise<void> to match the implementation, or modify the implementation to handle the return values appropriately.

Suggested change
environmentConfigResolved?: (
environment: PartialEnvironment,
) => boolean | Promise<boolean> | PluginOption
environmentConfigResolved?: (
environment: PartialEnvironment,
) => void | Promise<void>

Spotted by Diamond

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat: environment API Vite Environment API p2-nice-to-have Not breaking anything but nice to have (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants