Skip to content

Commit

Permalink
feat: check for moduleDirectories when externalizing dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored and fooddilsn committed May 25, 2023
1 parent d845d5e commit bab1cbe
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/vite-node/src/externalize.ts
Expand Up @@ -114,8 +114,11 @@ async function _shouldExternalize(
if (matchExternalizePattern(id, options?.external))
return id

const isNodeModule = id.includes('/node_modules/')
const guessCJS = isNodeModule && options?.fallbackCJS
const moduleDirectories = options?.moduleDirectories || ['/node_modules/']
const isLibraryModule = moduleDirectories.some(dir =>
dir instanceof RegExp ? dir.test(id) : id.includes(dir),
)
const guessCJS = isLibraryModule && options?.fallbackCJS
id = guessCJS ? (guessCJSversion(id) || id) : id

if (matchExternalizePattern(id, defaultInline))
Expand All @@ -124,7 +127,7 @@ async function _shouldExternalize(
return id

const isDist = id.includes('/dist/')
if ((isNodeModule || isDist) && await isValidNodeImport(id))
if ((isLibraryModule || isDist) && await isValidNodeImport(id))
return id

return false
Expand Down

0 comments on commit bab1cbe

Please sign in to comment.