Skip to content

Commit

Permalink
fix: remove plugin type extension (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBarre committed Dec 4, 2023
1 parent 74d996d commit 7f53c63
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
18 changes: 18 additions & 0 deletions packages/plugin-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 6 additions & 10 deletions packages/plugin-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)\$\(/
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 7f53c63

Please sign in to comment.