@@ -92,6 +92,7 @@ const react = (_options?: Options): PluginOption[] => {
9292 _options ?. useAtYourOwnRisk_mutateSwcOptions ,
9393 }
9494
95+ let base : string | undefined
9596 return [
9697 {
9798 name : 'vite:react-swc:resolve-runtime' ,
@@ -128,6 +129,7 @@ const react = (_options?: Options): PluginOption[] => {
128129 } ,
129130 } ) ,
130131 configResolved ( config ) {
132+ base = config . base
131133 if ( config . server . hmr === false ) hmrDisabled = true
132134 const mdxIndex = config . plugins . findIndex (
133135 ( p ) => p . name === '@mdx-js/rollup' ,
@@ -142,16 +144,23 @@ const react = (_options?: Options): PluginOption[] => {
142144 )
143145 }
144146 } ,
145- transformIndexHtml : ( _ , config ) => {
146- if ( ! hmrDisabled ) {
147- return [
148- {
149- tag : 'script' ,
150- attrs : { type : 'module' } ,
151- children : getPreambleCode ( config . server ! . config . base ) ,
152- } ,
153- ]
154- }
147+ transformIndexHtml : {
148+ handler ( ) {
149+ if ( ! hmrDisabled ) {
150+ return [
151+ {
152+ tag : 'script' ,
153+ attrs : { type : 'module' } ,
154+ // !!! Rolldown vite full bunlde module break changes, config.server is invalid
155+ // children: getPreambleCode(config.server!.config.base),
156+ children : getPreambleCode ( base ! ) ,
157+ } ,
158+ ]
159+ }
160+ } ,
161+ // Rolldown vite full bunlde module break changes.
162+ // Changed it to make sure the inject module could be bundled
163+ order : 'pre' ,
155164 } ,
156165 async transform ( code , _id , transformOptions ) {
157166 const id = _id . split ( '?' ) [ 0 ]
0 commit comments