@@ -117,6 +117,8 @@ export default function viteReact(opts: Options = {}): Plugin[] {
117117 let isProduction = true
118118 let projectRoot = process . cwd ( )
119119 let skipFastRefresh = true
120+ let base : string
121+ let isFullBundle = false
120122 let runPluginOverrides :
121123 | ( ( options : ReactBabelOptions , context : ReactBabelHookContext ) => void )
122124 | undefined
@@ -185,6 +187,11 @@ export default function viteReact(opts: Options = {}): Plugin[] {
185187 } ,
186188 configResolved ( config ) {
187189 runningInVite = true
190+ base = config . base
191+ // @ts -expect-error only available in newer rolldown-vite
192+ if ( config . experimental . fullBundleMode ) {
193+ isFullBundle = true
194+ }
188195 projectRoot = config . root
189196 isProduction = config . isProduction
190197 skipFastRefresh =
@@ -447,15 +454,20 @@ export default function viteReact(opts: Options = {}): Plugin[] {
447454 }
448455 } ,
449456 } ,
450- transformIndexHtml ( _ , config ) {
451- if ( ! skipFastRefresh )
452- return [
453- {
454- tag : 'script' ,
455- attrs : { type : 'module' } ,
456- children : getPreambleCode ( config . server ! . config . base ) ,
457- } ,
458- ]
457+ transformIndexHtml : {
458+ handler ( ) {
459+ if ( ! skipFastRefresh )
460+ return [
461+ {
462+ tag : 'script' ,
463+ attrs : { type : 'module' } ,
464+ children : getPreambleCode ( base ) ,
465+ } ,
466+ ]
467+ } ,
468+ // In unbundled mode, Vite transforms any requests.
469+ // But in full bundled mode, Vite only transforms / bundles the scripts injected in `order: 'pre'`.
470+ order : isFullBundle ? 'pre' : undefined ,
459471 } ,
460472 }
461473
0 commit comments