Skip to content

Commit

Permalink
fix: respect explicitily external/noExternal config (#8983)
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Jul 8, 2022
1 parent cf23963 commit e369880
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions packages/vite/src/node/ssr/ssrExternal.ts
Expand Up @@ -107,26 +107,30 @@ export function shouldExternalizeForSSR(

export function createIsConfiguredAsSsrExternal(
config: ResolvedConfig
): (id: string) => boolean {
): (id: string) => boolean | undefined {
const { ssr } = config
const noExternal = ssr?.noExternal
const noExternalFilter =
noExternal !== 'undefined' &&
typeof noExternal !== 'boolean' &&
createFilter(undefined, noExternal, { resolve: false })

// Returns true if it is configured as external, false if it is filtered
// by noExternal and undefined if it isn't affected by the explicit config
return (id: string) => {
const { ssr } = config
if (!ssr || ssr.external?.includes(id)) {
return true
}
if (typeof noExternal === 'boolean') {
return !noExternal
}
if (noExternalFilter) {
return noExternalFilter(id)
if (ssr) {
if (ssr.external?.includes(id)) {
return true
}
if (typeof noExternal === 'boolean') {
return !noExternal
}
if (noExternalFilter && !noExternalFilter(id)) {
return false
}
}
return true
return undefined
}
}

Expand Down Expand Up @@ -165,10 +169,11 @@ function createIsSsrExternal(
if (processedIds.has(id)) {
return processedIds.get(id)
}
const external =
!id.startsWith('.') &&
!path.isAbsolute(id) &&
(isBuiltin(id) || (isConfiguredAsExternal(id) && isValidPackageEntry(id)))
let external = false
if (!id.startsWith('.') && !path.isAbsolute(id)) {
external =
isBuiltin(id) || (isConfiguredAsExternal(id) ?? isValidPackageEntry(id))
}
processedIds.set(id, external)
return external
}
Expand Down

0 comments on commit e369880

Please sign in to comment.