Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: merge environments.ssr.resolve with root ssr config #18857

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions packages/vite/src/node/__tests__/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,63 @@ describe('resolveConfig', () => {
await resolveConfig({ root: './inc?ud#s', customLogger: logger }, 'build')
})
})

test('ssr config compat', async () => {
const config = await resolveConfig(
{
resolve: {
conditions: ['client1'],
},
ssr: {
resolve: {
conditions: ['ssr1'],
},
},
plugins: [
{
name: 'test',
config() {
return {
environments: {
client: {
resolve: {
conditions: ['client2'],
},
},
ssr: {
resolve: {
conditions: ['ssr2'],
},
},
},
}
},
},
],
},
'serve',
)
expect(config.resolve.conditions).toMatchInlineSnapshot(`
[
"client1",
]
`)
expect(config.environments.client.resolve.conditions).toMatchInlineSnapshot(`
[
"client1",
"client2",
]
`)
expect(config.ssr.resolve?.conditions).toMatchInlineSnapshot(`
[
"ssr1",
"ssr2",
]
`)
expect(config.environments.ssr.resolve?.conditions).toMatchInlineSnapshot(`
[
"ssr1",
"ssr2",
]
`)
Copy link
Collaborator Author

@hi-ogawa hi-ogawa Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enviornments.client.resolve is already merged with root resolve

config.environments[name] = mergeConfig(
name === 'client'
? defaultClientEnvironmentOptions
: defaultNonClientEnvironmentOptions,
config.environments[name],
)

I'm not sure why the difference of resolve.conditions and ssr.resolve.conditions. Let me take a closer look.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In e686c7d, I also made config.enviornments.client.resolve merge back to config.resolve

 expect(config.resolve.conditions).toMatchInlineSnapshot(`
    [
      "client1",
      "client2",
    ]
  `)

})
17 changes: 10 additions & 7 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1083,13 +1083,16 @@ export async function resolveConfig(
configEnvironmentsSsr.optimizeDeps ?? {},
)

configEnvironmentsSsr.resolve ??= {}
configEnvironmentsSsr.resolve.conditions ??= config.ssr?.resolve?.conditions
configEnvironmentsSsr.resolve.externalConditions ??=
config.ssr?.resolve?.externalConditions
configEnvironmentsSsr.resolve.mainFields ??= config.ssr?.resolve?.mainFields
configEnvironmentsSsr.resolve.external ??= config.ssr?.external
configEnvironmentsSsr.resolve.noExternal ??= config.ssr?.noExternal
configEnvironmentsSsr.resolve = mergeConfig(
{
conditions: config.ssr?.resolve?.conditions,
externalConditions: config.ssr?.resolve?.externalConditions,
mainFields: config.ssr?.resolve?.mainFields,
external: config.ssr?.external,
noExternal: config.ssr?.noExternal,
} satisfies EnvironmentResolveOptions,
configEnvironmentsSsr.resolve ?? {},
)
}

if (config.build?.ssrEmitAssets !== undefined) {
Expand Down