Skip to content
Merged
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
32 changes: 20 additions & 12 deletions packages/plugin-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { readFileSync } from 'node:fs'
import type * as babelCore from '@babel/core'
import type { ParserOptions, TransformOptions } from '@babel/core'
import { createFilter } from 'vite'
import * as vite from 'vite'
import type { Plugin, PluginOption, ResolvedConfig } from 'vite'
import {
addRefreshWrapper,
Expand Down Expand Up @@ -124,10 +125,24 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
enforce: 'pre',
config() {
if (opts.jsxRuntime === 'classic') {
return {
esbuild: {
jsx: 'transform',
},
if ('rolldownVersion' in vite) {
Copy link
Member Author

@sapphi-red sapphi-red Apr 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.meta does not exist in config hook (yet).

return {
oxc: {
jsx: {
runtime: 'classic',
// disable __self and __source injection even in dev
// as this plugin injects them by babel and oxc will throw
// if development is enabled and those properties are already present
development: false,
},
},
}
} else {
return {
esbuild: {
jsx: 'transform',
},
}
}
} else {
return {
Expand Down Expand Up @@ -203,14 +218,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
])
}

if (
opts.jsxRuntime === 'classic' &&
isJSX &&
// OXC injects self and source so these plugins are not needed for rolldown-vite
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore -- this.meta.rolldownVersion only exists in rolldown-vite
!this.meta.rolldownVersion
) {
if (opts.jsxRuntime === 'classic' && isJSX) {
if (!isProduction) {
// These development plugins are only needed for the classic runtime.
plugins.push(
Expand Down
Loading