@@ -85,6 +85,7 @@ type Options = {
85
85
86
86
const react = ( _options ?: Options ) : PluginOption [ ] => {
87
87
let hmrDisabled = false
88
+ let base : string
88
89
const options = {
89
90
jsxImportSource : _options ?. jsxImportSource ?? 'react' ,
90
91
tsDecorators : _options ?. tsDecorators ,
@@ -99,7 +100,6 @@ const react = (_options?: Options): PluginOption[] => {
99
100
disableOxcRecommendation : _options ?. disableOxcRecommendation ,
100
101
}
101
102
102
- let base : string | undefined
103
103
return [
104
104
{
105
105
name : 'vite:react-swc:resolve-runtime' ,
@@ -140,6 +140,8 @@ const react = (_options?: Options): PluginOption[] => {
140
140
configResolved ( config ) {
141
141
base = config . base
142
142
if ( config . server . hmr === false ) hmrDisabled = true
143
+ base = config . base
144
+
143
145
const mdxIndex = config . plugins . findIndex (
144
146
( p ) => p . name === '@mdx-js/rollup' ,
145
147
)
@@ -165,21 +167,19 @@ const react = (_options?: Options): PluginOption[] => {
165
167
}
166
168
} ,
167
169
transformIndexHtml : {
170
+ // TODO: maybe we can inject this to entrypoints instead of index.html?
168
171
handler ( ) {
169
- if ( ! hmrDisabled ) {
172
+ if ( ! hmrDisabled )
170
173
return [
171
174
{
172
175
tag : 'script' ,
173
176
attrs : { type : 'module' } ,
174
- // !!! Rolldown vite full bunlde module break changes, config.server is invalid
175
- // children: getPreambleCode(config.server!.config.base),
176
- children : getPreambleCode ( base ! ) ,
177
+ children : getPreambleCode ( base ) ,
177
178
} ,
178
179
]
179
- }
180
180
} ,
181
- // Rolldown vite full bunlde module break changes .
182
- // Changed it to make sure the inject module could be bundled
181
+ // In unbundled mode, Vite transforms any requests .
182
+ // But in full bundled mode, Vite only transforms / bundles the scripts injected in `order: 'pre'`.
183
183
order : 'pre' ,
184
184
} ,
185
185
async transform ( code , _id , transformOptions ) {
0 commit comments