Skip to content

Commit 2603932

Browse files
authored
fix: respect rollupOptions.platform options (#361)
1 parent b37507a commit 2603932

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,64 @@ describe('mergeConfig', () => {
556556
expect(upOutput.hashCharacters).toBe('base36')
557557
expect(downOutput.hashCharacters).toBe('base36')
558558
})
559+
560+
test('rollupOptions/rolldownOptions.platform', async () => {
561+
const testRollupOptions = await resolveConfig(
562+
{
563+
plugins: [
564+
{
565+
name: 'set-rollupOptions-platform',
566+
configEnvironment(name) {
567+
if (name === 'ssr') {
568+
return {
569+
build: {
570+
rollupOptions: {
571+
platform: 'neutral',
572+
},
573+
},
574+
}
575+
}
576+
},
577+
},
578+
],
579+
},
580+
'serve',
581+
)
582+
expect(
583+
testRollupOptions.environments.ssr.build.rolldownOptions.platform,
584+
).toBe('neutral')
585+
expect(
586+
testRollupOptions.environments.client.build.rolldownOptions.platform,
587+
).toBe('browser')
588+
589+
const testRolldownOptions = await resolveConfig(
590+
{
591+
plugins: [
592+
{
593+
name: 'set-rollupOptions-platform',
594+
configEnvironment(name) {
595+
if (name === 'ssr') {
596+
return {
597+
build: {
598+
rolldownOptions: {
599+
platform: 'neutral',
600+
},
601+
},
602+
}
603+
}
604+
},
605+
},
606+
],
607+
},
608+
'serve',
609+
)
610+
expect(
611+
testRolldownOptions.environments.ssr.build.rolldownOptions.platform,
612+
).toBe('neutral')
613+
expect(
614+
testRolldownOptions.environments.client.build.rolldownOptions.platform,
615+
).toBe('browser')
616+
})
559617
})
560618

561619
describe('resolveEnvPrefix', () => {

packages/vite/src/node/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,8 @@ export function resolveBuildEnvironmentOptions(
438438
)
439439
setupRollupOptionCompat(merged)
440440
merged.rolldownOptions = {
441-
...merged.rolldownOptions,
442441
platform: consumer === 'server' ? 'node' : 'browser',
442+
...merged.rolldownOptions,
443443
}
444444

445445
// handle special build targets

0 commit comments

Comments
 (0)