-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(vite6): re-apply default conditions if using vite 6 or later
Vite 6 no longer applies default conditions when you override resolve.conditions. This PR adds them back conditionally based on the vite version. Fixes #7070
- Loading branch information
thebanjomatic
committed
Dec 11, 2024
1 parent
4e60333
commit 379f9a8
Showing
3 changed files
with
43 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
function normalizeConditions(conditions?: string[]) { | ||
if (!conditions) { | ||
return [] | ||
} | ||
|
||
// We remove browser and node conditions from the default list because | ||
// we add back "node" explicitly in both client and server conditions. | ||
// this ensures that the conditions we pass on to vite doesn't include | ||
// both browser and node at the same time, or node twice in the server case. | ||
return conditions.filter(c => c !== 'browser' && c !== 'node') | ||
} | ||
|
||
async function getDefaultConditions() { | ||
type Vite6Options = typeof import('vite') & Partial<{ | ||
defaultClientConditions?: string[] | ||
defaultServerConditions?: string[] | ||
}> | ||
const vite: Vite6Options = await import('vite') | ||
|
||
return { | ||
defaultClientConditions: vite.defaultClientConditions, | ||
defaultServerConditions: vite.defaultServerConditions, | ||
} | ||
} | ||
|
||
export async function getConditions() { | ||
const { defaultClientConditions, defaultServerConditions } = await getDefaultConditions() | ||
return { | ||
clientConditions: ['node', ...normalizeConditions(defaultClientConditions)], | ||
serverConditions: ['node', ...normalizeConditions(defaultServerConditions)], | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters