Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/plugin-react-swc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Avoid `esbuild` warnings with Vite 8 [#1195](https://github.com/vitejs/vite-plugin-react/pull/1195)

Fixes [#1187](https://github.com/vitejs/vite-plugin-react/issues/1187).

## 4.3.0 (2026-03-12)

### Add Vite 8 to peerDependencies range [#1142](https://github.com/vitejs/vite-plugin-react/pull/1142)
Expand Down
76 changes: 49 additions & 27 deletions packages/plugin-react-swc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ type Options = {
disableOxcRecommendation?: boolean
}

const usingRolldown = 'rolldownVersion' in vite

const react = (_options?: Options): Plugin[] => {
let hmrDisabled = true
let viteCacheRoot: string | undefined
Expand Down Expand Up @@ -118,21 +120,27 @@ const react = (_options?: Options): Plugin[] => {
{
name: 'vite:react-swc',
apply: 'serve',
config: () => ({
esbuild: false,
// NOTE: oxc option only exists in rolldown-vite
oxc: false,
optimizeDeps: {
include: [`${options.jsxImportSource}/jsx-dev-runtime`],
...('rolldownVersion' in vite
? {
rolldownOptions: {
transform: { jsx: { runtime: 'automatic' } },
},
}
: { esbuildOptions: { jsx: 'automatic' } }),
},
}),
config: () => {
if (usingRolldown) {
return {
oxc: false,
optimizeDeps: {
include: [`${options.jsxImportSource}/jsx-dev-runtime`],
rolldownOptions: {
transform: { jsx: { runtime: 'automatic' } },
},
},
}
} else {
return {
esbuild: false,
optimizeDeps: {
include: [`${options.jsxImportSource}/jsx-dev-runtime`],
esbuildOptions: { jsx: 'automatic' },
},
}
}
},
configResolved(config) {
viteCacheRoot = config.cacheDir
hmrDisabled = config.server.hmr === false
Expand All @@ -150,7 +158,7 @@ const react = (_options?: Options): Plugin[] => {
}

if (
'rolldownVersion' in vite &&
usingRolldown &&
!options.plugins &&
!options.useAtYourOwnRisk_mutateSwcOptions &&
!options.disableOxcRecommendation
Expand Down Expand Up @@ -204,7 +212,7 @@ const react = (_options?: Options): Plugin[] => {
? {
name: 'vite:react-swc',
apply: 'build',
enforce: 'pre', // Run before esbuild
enforce: 'pre', // Run before esbuild/oxc
config: (userConfig) => ({
build: silenceUseClientWarning(userConfig),
}),
Expand All @@ -227,16 +235,30 @@ const react = (_options?: Options): Plugin[] => {
: {
name: 'vite:react-swc',
apply: 'build',
config: (userConfig) => ({
build: silenceUseClientWarning(userConfig),
esbuild: {
jsx: 'automatic',
jsxImportSource: options.jsxImportSource,
tsconfigRaw: {
compilerOptions: { useDefineForClassFields: true },
},
},
}),
config: (userConfig) => {
if (usingRolldown) {
return {
build: silenceUseClientWarning(userConfig),
oxc: {
jsx: {
runtime: 'automatic',
importSource: options.jsxImportSource,
},
},
}
} else {
return {
build: silenceUseClientWarning(userConfig),
esbuild: {
jsx: 'automatic',
jsxImportSource: options.jsxImportSource,
tsconfigRaw: {
compilerOptions: { useDefineForClassFields: true },
},
},
}
}
},
configResolved(config) {
viteCacheRoot = config.cacheDir
},
Expand Down
Loading