Skip to content

Commit 52aa8be

Browse files
committed
update swc and oxc plugins
1 parent fecb9a7 commit 52aa8be

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { readFileSync } from 'node:fs'
44
import type { BuildOptions, Plugin } from 'vite'
55
import {
66
addRefreshWrapper,
7-
getPreambleCode,
87
runtimePublicPath,
98
silenceUseClientWarning,
9+
virtualPreamblePlugin,
1010
} from '@vitejs/react-common'
1111
import { exactRegex } from '@rolldown/pluginutils'
1212

@@ -143,17 +143,15 @@ export default function viteReact(opts: Options = {}): Plugin[] {
143143
return newCode ? { code: newCode, map: null } : undefined
144144
},
145145
},
146-
transformIndexHtml(_, config) {
147-
if (!skipFastRefresh)
148-
return [
149-
{
150-
tag: 'script',
151-
attrs: { type: 'module' },
152-
children: getPreambleCode(config.server!.config.base),
153-
},
154-
]
155-
},
156146
}
157147

158-
return [viteConfig, viteConfigPost, viteRefreshRuntime, viteRefreshWrapper]
148+
return [
149+
viteConfig,
150+
viteConfigPost,
151+
viteRefreshRuntime,
152+
viteRefreshWrapper,
153+
virtualPreamblePlugin({
154+
isEnabled: () => !skipFastRefresh,
155+
}) as any, // rolldown-vite type mismatch
156+
]
159157
}

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import {
1313
import type { Plugin } from 'vite'
1414
import {
1515
addRefreshWrapper,
16-
getPreambleCode,
1716
runtimePublicPath,
1817
silenceUseClientWarning,
18+
virtualPreamblePlugin,
1919
} from '@vitejs/react-common'
2020
import * as vite from 'vite'
2121
import { exactRegex } from '@rolldown/pluginutils'
@@ -165,17 +165,6 @@ const react = (_options?: Options): Plugin[] => {
165165
)
166166
}
167167
},
168-
transformIndexHtml: (_, config) => {
169-
if (!hmrDisabled) {
170-
return [
171-
{
172-
tag: 'script',
173-
attrs: { type: 'module' },
174-
children: getPreambleCode(config.server!.config.base),
175-
},
176-
]
177-
}
178-
},
179168
async transform(code, _id, transformOptions) {
180169
const id = _id.split('?')[0]
181170
const refresh = !transformOptions?.ssr && !hmrDisabled
@@ -205,6 +194,10 @@ const react = (_options?: Options): Plugin[] => {
205194
return { code: newCode ?? result.code, map: result.map }
206195
},
207196
},
197+
virtualPreamblePlugin({
198+
isEnabled: () => !hmrDisabled,
199+
reactRefreshHost: options.reactRefreshHost,
200+
}),
208201
options.plugins
209202
? {
210203
name: 'vite:react-swc',

0 commit comments

Comments
 (0)