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: respect explicitily external/noExternal config #8983

Merged
merged 2 commits into from Jul 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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