Skip to content

feat: make PluginContext available for Vite-specific hooks #19936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

sapphi-red
Copy link
Member

@sapphi-red sapphi-red commented Apr 25, 2025

Description

Make PluginContext available for Vite-specific hooks.
By making PluginContext available, we have the following upsides:

Each hooks will receive the following plugin context types:

  • config: ConfigPluginContext
  • configEnvironment: ConfigPluginContext
  • configResolved: MinimalPluginContextWithoutEnvironment
  • handleHotUpdate: MinimalPluginContextWithoutEnvironment
  • transformIndexHtml: MinimalPluginContextWithoutEnvironment
  • configureServer: MinimalPluginContextWithoutEnvironment
  • configurePreviewServer: MinimalPluginContextWithoutEnvironment
  • hotUpdate: MinimalPluginContextWithoutEnvironment
  • buildApp: MinimalPluginContextWithoutEnvironment
  • handleHotUpdate: MinimalPluginContext & { environment: DevEnvironment }

ConfigPluginContext does not have access to this.meta.watchMode and this.environment.
MinimalPluginContextWithoutEnvironment does not have access to this.environment.

@sapphi-red sapphi-red added the p2-nice-to-have Not breaking anything but nice to have (priority) label Apr 25, 2025
patak-dev
patak-dev previously approved these changes Apr 25, 2025
Copy link
Member

@patak-dev patak-dev left a comment

Choose a reason for hiding this comment

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

looks like a great API extension to me

@sapphi-red sapphi-red added this to the 7.0 milestone May 14, 2025
@sapphi-red
Copy link
Member Author

I've resolved conflicts and added support for buildApp hook

patak-dev
patak-dev previously approved these changes May 19, 2025
@sapphi-red sapphi-red merged commit 7063839 into vitejs:main May 27, 2025
15 checks passed
@sapphi-red sapphi-red deleted the feat/make-plugin-context-available-in-vite-specific-hooks branch May 27, 2025 02:50
@patak-dev
Copy link
Member

@sapphi-red linking related ecosystem CI results from here too: #20115 (comment)

dai-shi pushed a commit to wakujs/waku that referenced this pull request May 29, 2025
While the current patch code works fine as `this` is `undefined` for
current Vite, Vite 7+ will pass the context
(vitejs/vite#19936) and the current code doesn't
work anymore.
This PR changes the code to call the hook function with the original
`this`.

This PR should fix the ecosystem-ci failure.

https://github.com/vitejs/vite-ecosystem-ci/actions/runs/15291891294/job/43012757791#step:8:665
fwouts pushed a commit to fwouts/previewjs that referenced this pull request Jun 3, 2025
While the current patch code works fine as `this` is `undefined` for
current Vite, Vite 7+ will pass the context
(vitejs/vite#19936) and the current code doesn't
work anymore.
This PR changes the code to call the hook function with the original
`this`.

This PR should fix the ecosystem-ci failure.

https://github.com/vitejs/vite-ecosystem-ci/actions/runs/15291891294/job/43012757742#step:8:3335
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

2 participants