Skip to content

Commit 7f53c63

Browse files
authored
fix: remove plugin type extension (#269)
1 parent 74d996d commit 7f53c63

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

packages/plugin-react/CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
## Unreleased
44

5+
Remove generic parameter on `Plugin` to avoid type error with Rollup 4/Vite 5 and `skipLibCheck: false`.
6+
7+
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`:
8+
9+
```ts
10+
import type { Plugin } from 'vite'
11+
import type { ViteReactPluginApi } from '@vitejs/plugin-react'
12+
13+
export const somePlugin: Plugin = {
14+
name: 'some-plugin',
15+
api: {
16+
reactBabel: (babelConfig) => {
17+
babelConfig.plugins.push('some-babel-plugin')
18+
},
19+
} satisfies ViteReactPluginApi,
20+
}
21+
```
22+
523
## 4.2.0 (2023-11-16)
624

725
### Update peer dependency range to target Vite 5

packages/plugin-react/src/index.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,11 @@ type ReactBabelHook = (
7979

8080
type ReactBabelHookContext = { ssr: boolean; id: string }
8181

82-
declare module 'vite' {
83-
export interface Plugin {
84-
api?: {
85-
/**
86-
* Manipulate the Babel options of `@vitejs/plugin-react`
87-
*/
88-
reactBabel?: ReactBabelHook
89-
}
90-
}
82+
export type ViteReactPluginApi = {
83+
/**
84+
* Manipulate the Babel options of `@vitejs/plugin-react`
85+
*/
86+
reactBabel?: ReactBabelHook
9187
}
9288

9389
const refreshContentRE = /\$Refresh(?:Reg|Sig)\$\(/
@@ -150,7 +146,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
150146
)
151147
}
152148

153-
const hooks = config.plugins
149+
const hooks: ReactBabelHook[] = config.plugins
154150
.map((plugin) => plugin.api?.reactBabel)
155151
.filter(defined)
156152

0 commit comments

Comments
 (0)