Skip to content

Commit

Permalink
fix: resolve.conditions in ResolvedConfig was defaultServerConditions
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Jan 10, 2025
1 parent 71506f0 commit ea98aa1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
32 changes: 32 additions & 0 deletions packages/vite/src/node/__tests__/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,3 +481,35 @@ test('config compat 2', async () => {
]
`)
})

test('config compat 3', async () => {
const config = await resolveConfig({}, 'serve')
expect(config.resolve.conditions).toMatchInlineSnapshot(`
[
"module",
"browser",
"development|production",
]
`)
expect(config.environments.client.resolve.conditions).toMatchInlineSnapshot(`
[
"module",
"browser",
"development|production",
]
`)
expect(config.ssr.resolve?.conditions).toMatchInlineSnapshot(`
[
"module",
"node",
"development|production",
]
`)
expect(config.environments.ssr.resolve?.conditions).toMatchInlineSnapshot(`
[
"module",
"node",
"development|production",
]
`)
})
9 changes: 7 additions & 2 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,7 @@ function resolveEnvironmentResolveOptions(
alias: Alias[],
preserveSymlinks: boolean,
logger: Logger,
/** undefined when resolving the top-level resolve options */
consumer: 'client' | 'server' | undefined,
// Backward compatibility
isSsrTargetWebworkerEnvironment?: boolean,
Expand All @@ -875,11 +876,15 @@ function resolveEnvironmentResolveOptions(
{
...configDefaults.resolve,
mainFields:
consumer === 'client' || isSsrTargetWebworkerEnvironment
consumer === undefined ||
consumer === 'client' ||
isSsrTargetWebworkerEnvironment
? DEFAULT_CLIENT_MAIN_FIELDS
: DEFAULT_SERVER_MAIN_FIELDS,
conditions:
consumer === 'client' || isSsrTargetWebworkerEnvironment
consumer === undefined ||
consumer === 'client' ||
isSsrTargetWebworkerEnvironment
? DEFAULT_CLIENT_CONDITIONS
: DEFAULT_SERVER_CONDITIONS.filter((c) => c !== 'browser'),
enableBuiltinNoExternalCheck: !!isSsrTargetWebworkerEnvironment,
Expand Down

0 comments on commit ea98aa1

Please sign in to comment.