Skip to content

Commit 3527191

Browse files
authored
fix: resolved build options should be kept as a getter (#22691)
1 parent 0d4a81f commit 3527191

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

‎packages/vite/src/node/__tests__/config.spec.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,26 @@ describe('mergeConfig', () => {
669669
).toBe('browser')
670670
})
671671

672+
test('resolved build options keep rollupOptions as a live proxy of rolldownOptions', async () => {
673+
const config = await resolveConfig({}, 'serve')
674+
675+
for (const build of [
676+
config.build,
677+
config.environments.client.build,
678+
config.environments.ssr.build,
679+
]) {
680+
// Reassigning `rolldownOptions` must be reflected through the `rollupOptions` getter.
681+
const newOptions = { treeshake: false }
682+
build.rolldownOptions = newOptions
683+
expect(build.rollupOptions).toBe(newOptions)
684+
685+
// Assigning through `rollupOptions` must update `rolldownOptions` too.
686+
const newerOptions = { treeshake: true }
687+
build.rollupOptions = newerOptions
688+
expect(build.rolldownOptions).toBe(newerOptions)
689+
}
690+
})
691+
672692
test('syncs `server.hmr.*` to `server.ws.*`', () => {
673693
const baseConfig = defineConfig({
674694
server: {

‎packages/vite/src/node/build.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,9 @@ export function resolveBuildEnvironmentOptions(
505505
...merged.modulePreload,
506506
},
507507
}
508+
// The object spread above evaluates the `rollupOptions` getter set up on
509+
// `merged` and copies it as a plain data property.
510+
setupRollupOptionCompat(resolved, 'build')
508511

509512
return resolved
510513
}

0 commit comments

Comments
 (0)