Skip to content

Commit 90bc034

Browse files
authored
fix: use top-level input for SSR build when build.ssr: true (#23898)
1 parent 28e1710 commit 90bc034

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,30 @@ describe('resolveConfig', () => {
15071507
expect(config.environments.ssr.build.rolldownOptions.input).toBeUndefined()
15081508
})
15091509

1510+
test('top-level input applies to the SSR environment when build.ssr is true in build', async () => {
1511+
const config = await resolveConfig(
1512+
{
1513+
input: 'src/entry-server.ts',
1514+
build: { ssr: true },
1515+
},
1516+
'build',
1517+
)
1518+
1519+
expect(config.environments.ssr.input).toBe('src/entry-server.ts')
1520+
})
1521+
1522+
test('top-level input does not apply to the SSR environment when build.ssr is true in dev', async () => {
1523+
const config = await resolveConfig(
1524+
{
1525+
input: 'src/entry-server.ts',
1526+
build: { ssr: true },
1527+
},
1528+
'serve',
1529+
)
1530+
1531+
expect(config.environments.ssr.input).toBeUndefined()
1532+
})
1533+
15101534
test('per-environment input overrides the top-level value', async () => {
15111535
const config = await resolveConfig(
15121536
{

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,6 +1714,10 @@ export async function resolveConfig(
17141714
},
17151715
}
17161716

1717+
if (isBuild && config.build?.ssr === true) {
1718+
config.environments.ssr.input ??= config.input
1719+
}
1720+
17171721
for (const name of Object.keys(config.environments)) {
17181722
config.environments[name] = mergeConfig(
17191723
name === 'client'

0 commit comments

Comments
 (0)