Skip to content

Commit e851bf8

Browse files
committed
chore: use ViteReactPluginApi
1 parent 256a545 commit e851bf8

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import assert from 'node:assert'
22
import rsc, { transformHoistInlineDirective } from '@vitejs/plugin-rsc'
33
import tailwindcss from '@tailwindcss/vite'
4-
import react from '@vitejs/plugin-react'
4+
import react, { type ViteReactPluginApi } from '@vitejs/plugin-react'
55
import { type Plugin, defineConfig, normalizePath, parseAstAsync } from 'vite'
66
import inspect from 'vite-plugin-inspect'
77
import path from 'node:path'
@@ -23,12 +23,20 @@ export default defineConfig({
2323
plugins: [
2424
tailwindcss(),
2525
process.env.TEST_REACT_COMPILER
26-
? react({ babel: { plugins: ['babel-plugin-react-compiler'] } }).map(
27-
(p: any) => ({
28-
...p,
29-
applyToEnvironment: (e: any) => e.name === 'client',
30-
}),
31-
)
26+
? [
27+
react({ babel: { plugins: ['babel-plugin-react-compiler'] } }),
28+
// skip react compiler in non CSR environments
29+
{
30+
name: 'react-babel-override',
31+
api: {
32+
reactBabel: (babelConfig, context) => {
33+
if (context.ssr) {
34+
babelConfig.plugins = []
35+
}
36+
},
37+
} satisfies ViteReactPluginApi,
38+
},
39+
]
3240
: react(),
3341
vitePluginUseCache(),
3442
rsc({

0 commit comments

Comments
 (0)