diff --git a/packages/plugin-react/CHANGELOG.md b/packages/plugin-react/CHANGELOG.md index 1717de4..6234141 100644 --- a/packages/plugin-react/CHANGELOG.md +++ b/packages/plugin-react/CHANGELOG.md @@ -2,6 +2,24 @@ ## Unreleased +Remove generic parameter on `Plugin` to avoid type error with Rollup 4/Vite 5 and `skipLibCheck: false`. + +I expect very few people to currently use this feature, but if you are extending the React plugin via `api` object, you can get back the typing of the hook by importing `ViteReactPluginApi`: + +```ts +import type { Plugin } from 'vite' +import type { ViteReactPluginApi } from '@vitejs/plugin-react' + +export const somePlugin: Plugin = { + name: 'some-plugin', + api: { + reactBabel: (babelConfig) => { + babelConfig.plugins.push('some-babel-plugin') + }, + } satisfies ViteReactPluginApi, +} +``` + ## 4.2.0 (2023-11-16) ### Update peer dependency range to target Vite 5 diff --git a/packages/plugin-react/src/index.ts b/packages/plugin-react/src/index.ts index c130851..1a13356 100644 --- a/packages/plugin-react/src/index.ts +++ b/packages/plugin-react/src/index.ts @@ -79,15 +79,11 @@ type ReactBabelHook = ( type ReactBabelHookContext = { ssr: boolean; id: string } -declare module 'vite' { - export interface Plugin { - api?: { - /** - * Manipulate the Babel options of `@vitejs/plugin-react` - */ - reactBabel?: ReactBabelHook - } - } +export type ViteReactPluginApi = { + /** + * Manipulate the Babel options of `@vitejs/plugin-react` + */ + reactBabel?: ReactBabelHook } const refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/ @@ -150,7 +146,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] { ) } - const hooks = config.plugins + const hooks: ReactBabelHook[] = config.plugins .map((plugin) => plugin.api?.reactBabel) .filter(defined)