File tree Expand file tree Collapse file tree 2 files changed +15
-24
lines changed Expand file tree Collapse file tree 2 files changed +15
-24
lines changed Original file line number Diff line number Diff line change @@ -4,9 +4,9 @@ import { readFileSync } from 'node:fs'
44import type { BuildOptions , Plugin } from 'vite'
55import {
66 addRefreshWrapper ,
7- getPreambleCode ,
87 runtimePublicPath ,
98 silenceUseClientWarning ,
9+ virtualPreamblePlugin ,
1010} from '@vitejs/react-common'
1111import { 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}
Original file line number Diff line number Diff line change @@ -13,9 +13,9 @@ import {
1313import type { Plugin } from 'vite'
1414import {
1515 addRefreshWrapper ,
16- getPreambleCode ,
1716 runtimePublicPath ,
1817 silenceUseClientWarning ,
18+ virtualPreamblePlugin ,
1919} from '@vitejs/react-common'
2020import * as vite from 'vite'
2121import { 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' ,
You can’t perform that action at this time.
0 commit comments