From 1451b78e7b1a34b89e2768315832087c686fb5aa Mon Sep 17 00:00:00 2001 From: Richard Petersen Date: Sun, 4 Apr 2021 07:33:47 +0200 Subject: [PATCH] fix: chunks are analysed multiple times (#2541) Co-authored-by: Richard Petersen --- packages/vite/src/node/plugins/importAnalysisBuild.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/vite/src/node/plugins/importAnalysisBuild.ts b/packages/vite/src/node/plugins/importAnalysisBuild.ts index 0baba266958434..70d364900d03e9 100644 --- a/packages/vite/src/node/plugins/importAnalysisBuild.ts +++ b/packages/vite/src/node/plugins/importAnalysisBuild.ts @@ -218,6 +218,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin { if (imports.length) { const s = new MagicString(code) + const analyzed: Set = new Set() for (let index = 0; index < imports.length; index++) { const { s: start, e: end, d: dynamicIndex } = imports[index] // if dynamic import polyfill is used, rewrite the import to @@ -234,6 +235,8 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin { // literal import - trace direct imports and add to deps const addDeps = (filename: string) => { if (filename === ownerFilename) return + if (analyzed.has(filename)) return + analyzed.add(filename) const chunk = bundle[filename] as OutputChunk | undefined if (chunk) { deps.add(config.base + chunk.fileName)