Skip to content

Commit e369880

Browse files
authored
fix: respect explicitily external/noExternal config (#8983)
1 parent cf23963 commit e369880

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

packages/vite/src/node/ssr/ssrExternal.ts

+19-14
Original file line numberDiff line numberDiff line change
@@ -107,26 +107,30 @@ export function shouldExternalizeForSSR(
107107

108108
export function createIsConfiguredAsSsrExternal(
109109
config: ResolvedConfig
110-
): (id: string) => boolean {
110+
): (id: string) => boolean | undefined {
111111
const { ssr } = config
112112
const noExternal = ssr?.noExternal
113113
const noExternalFilter =
114114
noExternal !== 'undefined' &&
115115
typeof noExternal !== 'boolean' &&
116116
createFilter(undefined, noExternal, { resolve: false })
117117

118+
// Returns true if it is configured as external, false if it is filtered
119+
// by noExternal and undefined if it isn't affected by the explicit config
118120
return (id: string) => {
119121
const { ssr } = config
120-
if (!ssr || ssr.external?.includes(id)) {
121-
return true
122-
}
123-
if (typeof noExternal === 'boolean') {
124-
return !noExternal
125-
}
126-
if (noExternalFilter) {
127-
return noExternalFilter(id)
122+
if (ssr) {
123+
if (ssr.external?.includes(id)) {
124+
return true
125+
}
126+
if (typeof noExternal === 'boolean') {
127+
return !noExternal
128+
}
129+
if (noExternalFilter && !noExternalFilter(id)) {
130+
return false
131+
}
128132
}
129-
return true
133+
return undefined
130134
}
131135
}
132136

@@ -165,10 +169,11 @@ function createIsSsrExternal(
165169
if (processedIds.has(id)) {
166170
return processedIds.get(id)
167171
}
168-
const external =
169-
!id.startsWith('.') &&
170-
!path.isAbsolute(id) &&
171-
(isBuiltin(id) || (isConfiguredAsExternal(id) && isValidPackageEntry(id)))
172+
let external = false
173+
if (!id.startsWith('.') && !path.isAbsolute(id)) {
174+
external =
175+
isBuiltin(id) || (isConfiguredAsExternal(id) ?? isValidPackageEntry(id))
176+
}
172177
processedIds.set(id, external)
173178
return external
174179
}

0 commit comments

Comments
 (0)