Skip to content

Commit 11f56d6

Browse files
authored
fix: return Plugin[] instead of PluginOption[] (#537)
1 parent 442e46e commit 11f56d6

File tree

7 files changed

+23
-9
lines changed

7 files changed

+23
-9
lines changed

packages/plugin-react-oxc/CHANGELOG.md

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

33
## Unreleased
44

5+
### Return `Plugin[]` instead of `PluginOption[]`
6+
57
## 0.2.3 (2025-06-16)
68

79
### Disable refresh transform when `server.hmr: false` is set [#502](https://github.com/vitejs/vite-plugin-react/pull/502)

packages/plugin-react-oxc/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { dirname, join } from 'node:path'
22
import { fileURLToPath } from 'node:url'
33
import { readFileSync } from 'node:fs'
4-
import type { BuildOptions, Plugin, PluginOption } from 'vite'
4+
import type { BuildOptions, Plugin } from 'vite'
55
import {
66
addRefreshWrapper,
77
avoidSourceMapOption,
@@ -30,7 +30,7 @@ export interface Options {
3030

3131
const defaultIncludeRE = /\.[tj]sx?(?:$|\?)/
3232

33-
export default function viteReact(opts: Options = {}): PluginOption[] {
33+
export default function viteReact(opts: Options = {}): Plugin[] {
3434
const include = opts.include ?? defaultIncludeRE
3535
const exclude = [
3636
...(Array.isArray(opts.exclude)

packages/plugin-react-swc/CHANGELOG.md

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

33
## Unreleased
44

5+
### Return `Plugin[]` instead of `PluginOption[]`
6+
57
## 3.10.2 (2025-06-10)
68

79
### Suggest `@vitejs/plugin-react-oxc` if rolldown-vite is detected [#491](https://github.com/vitejs/vite-plugin-react/pull/491)

packages/plugin-react-swc/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
type Options as SWCOptions,
1212
transform,
1313
} from '@swc/core'
14-
import type { PluginOption } from 'vite'
14+
import type { Plugin } from 'vite'
1515
import {
1616
addRefreshWrapper,
1717
getPreambleCode,
@@ -83,7 +83,7 @@ type Options = {
8383
disableOxcRecommendation?: boolean
8484
}
8585

86-
const react = (_options?: Options): PluginOption[] => {
86+
const react = (_options?: Options): Plugin[] => {
8787
let hmrDisabled = false
8888
const options = {
8989
jsxImportSource: _options?.jsxImportSource ?? 'react',

packages/plugin-react/CHANGELOG.md

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

33
## Unreleased
44

5+
### Return `Plugin[]` instead of `PluginOption[]`
6+
7+
The return type has changed from `react(): PluginOption[]` to more specialized type `react(): Plugin[]`. This allows for type-safe manipulation of plugins, for example:
8+
9+
```tsx
10+
// previously this causes type errors
11+
react({ babel: { plugins: ['babel-plugin-react-compiler'] } })
12+
.map(p => ({ ...p, applyToEnvironment: e => e.name === 'client' }))
13+
```
14+
515
## 4.6.0 (2025-06-23)
616

717
### Add raw Rolldown support

packages/plugin-react/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type * as babelCore from '@babel/core'
55
import type { ParserOptions, TransformOptions } from '@babel/core'
66
import { createFilter } from 'vite'
77
import * as vite from 'vite'
8-
import type { Plugin, PluginOption, ResolvedConfig } from 'vite'
8+
import type { Plugin, ResolvedConfig } from 'vite'
99
import {
1010
addRefreshWrapper,
1111
getPreambleCode,
@@ -109,7 +109,7 @@ export type ViteReactPluginApi = {
109109
const defaultIncludeRE = /\.[tj]sx?$/
110110
const tsRE = /\.tsx?$/
111111

112-
export default function viteReact(opts: Options = {}): PluginOption[] {
112+
export default function viteReact(opts: Options = {}): Plugin[] {
113113
const include = opts.include ?? defaultIncludeRE
114114
const exclude = opts.exclude
115115
const filter = createFilter(include, exclude)

packages/plugin-rsc/examples/basic/vite.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ export default defineConfig({
2323
plugins: [
2424
tailwindcss(),
2525
process.env.TEST_REACT_COMPILER
26-
? (react({
26+
? react({
2727
babel: { plugins: ['babel-plugin-react-compiler'] },
2828
}).map((p) => ({
2929
...p,
30-
applyToEnvironment: (e: any) => e.name === 'client',
31-
})) as any)
30+
applyToEnvironment: (e) => e.name === 'client',
31+
}))
3232
: react(),
3333
vitePluginUseCache(),
3434
rsc({

0 commit comments

Comments
 (0)