@@ -18,6 +18,7 @@ import {
1818 runtimePublicPath ,
1919 silenceUseClientWarning ,
2020} from '@vitejs/react-common'
21+ import { exactRegex } from '@rolldown/pluginutils'
2122
2223/* eslint-disable no-restricted-globals */
2324const _dirname =
@@ -96,14 +97,23 @@ const react = (_options?: Options): PluginOption[] => {
9697 name : 'vite:react-swc:resolve-runtime' ,
9798 apply : 'serve' ,
9899 enforce : 'pre' , // Run before Vite default resolve to avoid syscalls
99- resolveId : ( id ) => ( id === runtimePublicPath ? id : undefined ) ,
100- load : ( id ) =>
101- id === runtimePublicPath
102- ? readFileSync ( join ( _dirname , 'refresh-runtime.js' ) , 'utf-8' ) . replace (
103- / _ _ R E A D M E _ U R L _ _ / g,
104- 'https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react-swc' ,
105- )
106- : undefined ,
100+ resolveId : {
101+ filter : { id : exactRegex ( runtimePublicPath ) } ,
102+ handler : ( id ) => ( id === runtimePublicPath ? id : undefined ) ,
103+ } ,
104+ load : {
105+ filter : { id : exactRegex ( runtimePublicPath ) } ,
106+ handler : ( id ) =>
107+ id === runtimePublicPath
108+ ? readFileSync (
109+ join ( _dirname , 'refresh-runtime.js' ) ,
110+ 'utf-8' ,
111+ ) . replace (
112+ / _ _ R E A D M E _ U R L _ _ / g,
113+ 'https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react-swc' ,
114+ )
115+ : undefined ,
116+ } ,
107117 } ,
108118 {
109119 name : 'vite:react-swc' ,
@@ -132,13 +142,17 @@ const react = (_options?: Options): PluginOption[] => {
132142 )
133143 }
134144 } ,
135- transformIndexHtml : ( _ , config ) => [
136- {
137- tag : 'script' ,
138- attrs : { type : 'module' , async : 'true' } ,
139- children : getPreambleCode ( config . server ! . config . base ) ,
140- } ,
141- ] ,
145+ transformIndexHtml : ( _ , config ) => {
146+ if ( ! hmrDisabled ) {
147+ return [
148+ {
149+ tag : 'script' ,
150+ attrs : { type : 'module' , async : 'true' } ,
151+ children : getPreambleCode ( config . server ! . config . base ) ,
152+ } ,
153+ ]
154+ }
155+ } ,
142156 async transform ( code , _id , transformOptions ) {
143157 const id = _id . split ( '?' ) [ 0 ]
144158 const refresh = ! transformOptions ?. ssr && ! hmrDisabled
0 commit comments