From 7b99c04f8a47b503ee92a7d0b10805f03744a6f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maty=C3=A1=C5=A1=20Racek?= Date: Sun, 17 Mar 2024 10:14:44 +0100 Subject: [PATCH 1/3] reduce size of injected __vite__mapDeps code This also replaces the lazy initialization of with eager one. --- packages/vite/src/node/plugins/importAnalysisBuild.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/vite/src/node/plugins/importAnalysisBuild.ts b/packages/vite/src/node/plugins/importAnalysisBuild.ts index 718ff6190cfeac..f0d149bdc97cfb 100644 --- a/packages/vite/src/node/plugins/importAnalysisBuild.ts +++ b/packages/vite/src/node/plugins/importAnalysisBuild.ts @@ -511,13 +511,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('#!')) { From 0418a94034a06b077a0c23658e14e36eaea0f119 Mon Sep 17 00:00:00 2001 From: bluwy Date: Mon, 18 Mar 2024 16:42:28 +0800 Subject: [PATCH 2/3] fix: add semicolon --- packages/vite/src/node/plugins/importAnalysisBuild.ts | 2 +- playground/js-sourcemap/__tests__/js-sourcemap.spec.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/plugins/importAnalysisBuild.ts b/packages/vite/src/node/plugins/importAnalysisBuild.ts index f0d149bdc97cfb..9641c9d7f10c86 100644 --- a/packages/vite/src/node/plugins/importAnalysisBuild.ts +++ b/packages/vite/src/node/plugins/importAnalysisBuild.ts @@ -511,7 +511,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin { ) .join(',')}]` - const mapDepsCode = `const __vite__fileDeps=${fileDepsCode},__vite__mapDeps=i=>i.map(i=>__vite__fileDeps[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 fd5d91a26af1b1..001c51b116c00a 100644 --- a/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts +++ b/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts @@ -138,7 +138,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", ], From dcadd3487091d435dd750f8a026ddf89e57e5477 Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Fri, 29 Mar 2024 17:28:57 +0900 Subject: [PATCH 3/3] chore: fix test --- playground/js-sourcemap/__tests__/js-sourcemap.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts b/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts index 43b31e46ac6a32..8e46cd63c6a327 100644 --- a/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts +++ b/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts @@ -162,7 +162,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=['), ]) })