Skip to content

Commit

Permalink
fix(build): should move module imported by entry to default vendor (v…
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Apr 10, 2021
1 parent 89898d3 commit 0ae2ada
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,14 +557,14 @@ function createMoveToVendorChunkFn(config: ResolvedConfig): GetManualChunk {
if (
id.includes('node_modules') &&
!isCSSRequest(id) &&
!hasDynamicImporter(id, getModuleInfo, cache)
staticImportedByEntry(id, getModuleInfo, cache)
) {
return 'vendor'
}
}
}

function hasDynamicImporter(
function staticImportedByEntry(
id: string,
getModuleInfo: GetModuleInfo,
cache: Map<string, boolean>,
Expand All @@ -583,15 +583,21 @@ function hasDynamicImporter(
cache.set(id, false)
return false
}
if (mod.dynamicImporters.length) {

if (mod.isEntry) {
cache.set(id, true)
return true
}
const someImporterHas = mod.importers.some((importer) =>
hasDynamicImporter(importer, getModuleInfo, cache, importStack.concat(id))
const someImporterIs = mod.importers.some((importer) =>
staticImportedByEntry(
importer,
getModuleInfo,
cache,
importStack.concat(id)
)
)
cache.set(id, someImporterHas)
return someImporterHas
cache.set(id, someImporterIs)
return someImporterIs
}

function resolveBuildOutputs(
Expand Down

0 comments on commit 0ae2ada

Please sign in to comment.