Skip to content

Commit ebd9b09

Browse files
authored
fix(react-swc): avoid esbuild warnings with Vite 8 (#1195)
1 parent 0389922 commit ebd9b09

File tree

2 files changed

+53
-27
lines changed

2 files changed

+53
-27
lines changed

packages/plugin-react-swc/CHANGELOG.md

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

33
## Unreleased
44

5+
### Avoid `esbuild` warnings with Vite 8 [#1195](https://github.com/vitejs/vite-plugin-react/pull/1195)
6+
7+
Fixes [#1187](https://github.com/vitejs/vite-plugin-react/issues/1187).
8+
59
## 4.3.0 (2026-03-12)
610

711
### Add Vite 8 to peerDependencies range [#1142](https://github.com/vitejs/vite-plugin-react/pull/1142)

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

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ type Options = {
7474
disableOxcRecommendation?: boolean
7575
}
7676

77+
const usingRolldown = 'rolldownVersion' in vite
78+
7779
const react = (_options?: Options): Plugin[] => {
7880
let hmrDisabled = true
7981
let viteCacheRoot: string | undefined
@@ -118,21 +120,27 @@ const react = (_options?: Options): Plugin[] => {
118120
{
119121
name: 'vite:react-swc',
120122
apply: 'serve',
121-
config: () => ({
122-
esbuild: false,
123-
// NOTE: oxc option only exists in rolldown-vite
124-
oxc: false,
125-
optimizeDeps: {
126-
include: [`${options.jsxImportSource}/jsx-dev-runtime`],
127-
...('rolldownVersion' in vite
128-
? {
129-
rolldownOptions: {
130-
transform: { jsx: { runtime: 'automatic' } },
131-
},
132-
}
133-
: { esbuildOptions: { jsx: 'automatic' } }),
134-
},
135-
}),
123+
config: () => {
124+
if (usingRolldown) {
125+
return {
126+
oxc: false,
127+
optimizeDeps: {
128+
include: [`${options.jsxImportSource}/jsx-dev-runtime`],
129+
rolldownOptions: {
130+
transform: { jsx: { runtime: 'automatic' } },
131+
},
132+
},
133+
}
134+
} else {
135+
return {
136+
esbuild: false,
137+
optimizeDeps: {
138+
include: [`${options.jsxImportSource}/jsx-dev-runtime`],
139+
esbuildOptions: { jsx: 'automatic' },
140+
},
141+
}
142+
}
143+
},
136144
configResolved(config) {
137145
viteCacheRoot = config.cacheDir
138146
hmrDisabled = config.server.hmr === false
@@ -150,7 +158,7 @@ const react = (_options?: Options): Plugin[] => {
150158
}
151159

152160
if (
153-
'rolldownVersion' in vite &&
161+
usingRolldown &&
154162
!options.plugins &&
155163
!options.useAtYourOwnRisk_mutateSwcOptions &&
156164
!options.disableOxcRecommendation
@@ -204,7 +212,7 @@ const react = (_options?: Options): Plugin[] => {
204212
? {
205213
name: 'vite:react-swc',
206214
apply: 'build',
207-
enforce: 'pre', // Run before esbuild
215+
enforce: 'pre', // Run before esbuild/oxc
208216
config: (userConfig) => ({
209217
build: silenceUseClientWarning(userConfig),
210218
}),
@@ -227,16 +235,30 @@ const react = (_options?: Options): Plugin[] => {
227235
: {
228236
name: 'vite:react-swc',
229237
apply: 'build',
230-
config: (userConfig) => ({
231-
build: silenceUseClientWarning(userConfig),
232-
esbuild: {
233-
jsx: 'automatic',
234-
jsxImportSource: options.jsxImportSource,
235-
tsconfigRaw: {
236-
compilerOptions: { useDefineForClassFields: true },
237-
},
238-
},
239-
}),
238+
config: (userConfig) => {
239+
if (usingRolldown) {
240+
return {
241+
build: silenceUseClientWarning(userConfig),
242+
oxc: {
243+
jsx: {
244+
runtime: 'automatic',
245+
importSource: options.jsxImportSource,
246+
},
247+
},
248+
}
249+
} else {
250+
return {
251+
build: silenceUseClientWarning(userConfig),
252+
esbuild: {
253+
jsx: 'automatic',
254+
jsxImportSource: options.jsxImportSource,
255+
tsconfigRaw: {
256+
compilerOptions: { useDefineForClassFields: true },
257+
},
258+
},
259+
}
260+
}
261+
},
240262
configResolved(config) {
241263
viteCacheRoot = config.cacheDir
242264
},

0 commit comments

Comments
 (0)