Skip to content

Commit 7b55598

Browse files
chore: check for babel hooks and disable if needed
1 parent 8ee3ad1 commit 7b55598

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,13 @@ const react = (_options?: Options): PluginOption[] => {
153153
* Suggest to use vite-plugin-react-oxc if `rolldown-vite` is used and:
154154
* No swc plugins are set
155155
* mutateSwcOptions is not set
156+
* It is not disabled by the user
156157
*/
157158
if (
158159
'rolldownVersion' in vite &&
159-
!options.disableOxcRecommendation &&
160+
!options.plugins &&
160161
!options.useAtYourOwnRisk_mutateSwcOptions &&
161-
!options.plugins
162+
!options.disableOxcRecommendation
162163
) {
163164
config.logger.warn(
164165
'[vite:react-swc] We recommend switching to `vite-plugin-react-oxc` for improved performance as no swc plugins are used. More information at https://vite.dev/rolldown',

packages/plugin-react/src/index.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,17 +174,6 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
174174
config.command === 'build' ||
175175
config.server.hmr === false
176176

177-
if (
178-
'rolldownVersion' in vite &&
179-
!opts.disableOxcRecommendation &&
180-
!opts.babel
181-
) {
182-
// Suggest to use vite-plugin-react-oxc if `rolldown-vite` is used and no babel config is set
183-
config.logger.warn(
184-
'[vite:react-babel] We recommend switching to `vite-plugin-react-oxc` for improved performance. More information at https://vite.dev/rolldown',
185-
)
186-
}
187-
188177
if ('jsxPure' in opts) {
189178
config.logger.warnOnce(
190179
'[@vitejs/plugin-react] jsxPure was removed. You can configure esbuild.jsxSideEffects directly.',
@@ -195,6 +184,23 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
195184
.map((plugin) => plugin.api?.reactBabel)
196185
.filter(defined)
197186

187+
if (
188+
'rolldownVersion' in vite &&
189+
!opts.babel &&
190+
!hooks.length &&
191+
!opts.disableOxcRecommendation
192+
) {
193+
/*
194+
* Suggest to use vite-plugin-react-oxc if `rolldown-vite` is used and:
195+
* No babel config is set
196+
* No other plugin is using the `api.reactBabel` hook
197+
* It is not disabled by the user
198+
*/
199+
config.logger.warn(
200+
'[vite:react-babel] We recommend switching to `vite-plugin-react-oxc` for improved performance. More information at https://vite.dev/rolldown',
201+
)
202+
}
203+
198204
if (hooks.length > 0) {
199205
runPluginOverrides = (babelOptions, context) => {
200206
hooks.forEach((hook) => hook(babelOptions, context, config))

0 commit comments

Comments
 (0)