@@ -117,6 +117,8 @@ export default function viteReact(opts: Options = {}): Plugin[] {
117
117
let isProduction = true
118
118
let projectRoot = process . cwd ( )
119
119
let skipFastRefresh = true
120
+ let base : string
121
+ let isFullBundle = false
120
122
let runPluginOverrides :
121
123
| ( ( options : ReactBabelOptions , context : ReactBabelHookContext ) => void )
122
124
| undefined
@@ -185,6 +187,11 @@ export default function viteReact(opts: Options = {}): Plugin[] {
185
187
} ,
186
188
configResolved ( config ) {
187
189
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
+ }
188
195
projectRoot = config . root
189
196
isProduction = config . isProduction
190
197
skipFastRefresh =
@@ -447,15 +454,20 @@ export default function viteReact(opts: Options = {}): Plugin[] {
447
454
}
448
455
} ,
449
456
} ,
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 ,
459
471
} ,
460
472
}
461
473
0 commit comments