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: vitepress/theme in ssrExternals #5651

Merged
merged 1 commit into from
Nov 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/vite/src/node/ssr/ssrExternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from 'path'
import { tryNodeResolve, InternalResolveOptions } from '../plugins/resolve'
import {
createDebugger,
isDefined,
lookupFile,
normalizePath,
resolveFrom
Expand Down Expand Up @@ -39,7 +40,8 @@ export function resolveSSRExternal(
seen
)

for (const dep of knownImports) {
const importedDeps = knownImports.map(getNpmPackageName).filter(isDefined)
for (const dep of importedDeps) {
// Assume external if not yet seen
// At this point, the project root and any linked packages have had their dependencies checked,
// so we can safely mark any knownImports not yet seen as external. They are guaranteed to be
Expand Down Expand Up @@ -172,3 +174,13 @@ export function shouldExternalizeForSSR(
})
return should
}

function getNpmPackageName(importPath: string): string | null {
const parts = importPath.split('/')
if (parts[0].startsWith('@')) {
if (!parts[1]) return null
return `${parts[0]}/${parts[1]}`
} else {
return parts[0]
}
}