Skip to content

Commit db0a431

Browse files
committed
feat: full bundle mode compat
1 parent 80df894 commit db0a431

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

packages/plugin-react/src/index.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)