Skip to content

Commit

Permalink
fix: ssrExternal should not skip nested dependencies (#7154)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Mar 14, 2022
1 parent a8dda1b commit f8f934a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/vite/src/node/ssr/__tests__/ssrExternal.spec.ts
@@ -0,0 +1,5 @@
import { stripNesting } from '../ssrExternal'

test('stripNesting', async () => {
expect(stripNesting(['c', 'p1>c1', 'p2 > c2'])).toEqual(['c', 'c1', 'c2'])
})
14 changes: 14 additions & 0 deletions packages/vite/src/node/ssr/ssrExternal.ts
Expand Up @@ -14,6 +14,16 @@ import { createFilter } from '@rollup/pluginutils'

const debug = createDebugger('vite:ssr-external')

/**
* Converts "parent > child" syntax to just "child"
*/
export function stripNesting(packages: string[]) {
return packages.map((s) => {
const arr = s.split('>')
return arr[arr.length - 1].trim()
})
}

/**
* Heuristics for determining whether a dependency should be externalized for
* server-side rendering.
Expand All @@ -22,6 +32,10 @@ export function resolveSSRExternal(
config: ResolvedConfig,
knownImports: string[]
): string[] {
// strip nesting since knownImports may be passed in from optimizeDeps which
// supports a "parent > child" syntax
knownImports = stripNesting(knownImports)

const ssrConfig = config.ssr
if (ssrConfig?.noExternal === true) {
return []
Expand Down

0 comments on commit f8f934a

Please sign in to comment.