diff --git a/packages/vite/src/node/plugins/importAnalysisBuild.ts b/packages/vite/src/node/plugins/importAnalysisBuild.ts index d7f6491ceb7306..2c3fdcee0e7e23 100644 --- a/packages/vite/src/node/plugins/importAnalysisBuild.ts +++ b/packages/vite/src/node/plugins/importAnalysisBuild.ts @@ -514,13 +514,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin { ) .join(',')}]` - const mapDepsCode = `\ -function __vite__mapDeps(indexes) { - if (!__vite__mapDeps.viteFileDeps) { - __vite__mapDeps.viteFileDeps = ${fileDepsCode} - } - return indexes.map((i) => __vite__mapDeps.viteFileDeps[i]) -}\n` + const mapDepsCode = `const __vite__fileDeps=${fileDepsCode},__vite__mapDeps=i=>i.map(i=>__vite__fileDeps[i]);\n` // inject extra code at the top or next line of hashbang if (code.startsWith('#!')) { diff --git a/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts b/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts index 1566549293efdb..15d82acd776283 100644 --- a/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts +++ b/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts @@ -140,7 +140,7 @@ describe.runIf(isBuild)('build tests', () => { expect(formatSourcemapForSnapshot(JSON.parse(map))).toMatchInlineSnapshot(` { "ignoreList": [], - "mappings": ";;;;;;w+BAAA,OAAO,2BAAuB,EAAC,wBAE/B,QAAQ,IAAI,uBAAuB", + "mappings": ";w+BAAA,OAAO,2BAAuB,EAAC,wBAE/B,QAAQ,IAAI,uBAAuB", "sources": [ "../../after-preload-dynamic.js", ], @@ -164,7 +164,7 @@ describe.runIf(isBuild)('build tests', () => { const js = findAssetFile(/after-preload-dynamic-hashbang-[-\w]{8}\.js$/) expect(js.split('\n').slice(0, 2)).toEqual([ '#!/usr/bin/env node', - 'function __vite__mapDeps(indexes) {', + expect.stringContaining('const __vite__fileDeps=['), ]) })