@@ -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 =
@@ -434,6 +441,27 @@ export default function viteReact(opts: Options = {}): Plugin[] {
434441 } ,
435442 }
436443
444+ // for rolldown-vite + full bundle mode
445+ const viteReactRefreshFullBundleMode : Plugin = {
446+ name : 'vite:react-refresh-fbm' ,
447+ enforce : 'pre' ,
448+ transformIndexHtml : {
449+ handler ( ) {
450+ if ( ! skipFastRefresh && isFullBundle )
451+ return [
452+ {
453+ tag : 'script' ,
454+ attrs : { type : 'module' } ,
455+ children : getPreambleCode ( base ) ,
456+ } ,
457+ ]
458+ } ,
459+ // In unbundled mode, Vite transforms any requests.
460+ // But in full bundled mode, Vite only transforms / bundles the scripts injected in `order: 'pre'`.
461+ order : 'pre' ,
462+ } ,
463+ }
464+
437465 const dependencies = [
438466 'react' ,
439467 'react-dom' ,
@@ -477,21 +505,23 @@ export default function viteReact(opts: Options = {}): Plugin[] {
477505 }
478506 } ,
479507 } ,
480- transformIndexHtml ( _ , config ) {
481- if ( ! skipFastRefresh )
508+ transformIndexHtml ( ) {
509+ if ( ! skipFastRefresh && ! isFullBundle )
482510 return [
483511 {
484512 tag : 'script' ,
485513 attrs : { type : 'module' } ,
486- children : getPreambleCode ( config . server ! . config . base ) ,
514+ children : getPreambleCode ( base ) ,
487515 } ,
488516 ]
489517 } ,
490518 }
491519
492520 return [
493521 viteBabel ,
494- ...( isRolldownVite ? [ viteRefreshWrapper , viteConfigPost ] : [ ] ) ,
522+ ...( isRolldownVite
523+ ? [ viteRefreshWrapper , viteConfigPost , viteReactRefreshFullBundleMode ]
524+ : [ ] ) ,
495525 viteReactRefresh ,
496526 ]
497527}
0 commit comments