Skip to content

Commit c0ec6be

Browse files
panstromekbluwysapphi-red
authoredApr 5, 2024··
perf: reduce size of injected __vite__mapDeps code (#16184)
Co-authored-by: bluwy <bjornlu.dev@gmail.com> Co-authored-by: 翠 / green <green@sapphi.red> Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
1 parent b762517 commit c0ec6be

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed
 

‎packages/vite/src/node/plugins/importAnalysisBuild.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -514,13 +514,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
514514
)
515515
.join(',')}]`
516516

517-
const mapDepsCode = `\
518-
function __vite__mapDeps(indexes) {
519-
if (!__vite__mapDeps.viteFileDeps) {
520-
__vite__mapDeps.viteFileDeps = ${fileDepsCode}
521-
}
522-
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
523-
}\n`
517+
const mapDepsCode = `const __vite__fileDeps=${fileDepsCode},__vite__mapDeps=i=>i.map(i=>__vite__fileDeps[i]);\n`
524518

525519
// inject extra code at the top or next line of hashbang
526520
if (code.startsWith('#!')) {

‎playground/js-sourcemap/__tests__/js-sourcemap.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ describe.runIf(isBuild)('build tests', () => {
140140
expect(formatSourcemapForSnapshot(JSON.parse(map))).toMatchInlineSnapshot(`
141141
{
142142
"ignoreList": [],
143-
"mappings": ";;;;;;w+BAAA,OAAO,2BAAuB,EAAC,wBAE/B,QAAQ,IAAI,uBAAuB",
143+
"mappings": ";w+BAAA,OAAO,2BAAuB,EAAC,wBAE/B,QAAQ,IAAI,uBAAuB",
144144
"sources": [
145145
"../../after-preload-dynamic.js",
146146
],
@@ -164,7 +164,7 @@ describe.runIf(isBuild)('build tests', () => {
164164
const js = findAssetFile(/after-preload-dynamic-hashbang-[-\w]{8}\.js$/)
165165
expect(js.split('\n').slice(0, 2)).toEqual([
166166
'#!/usr/bin/env node',
167-
'function __vite__mapDeps(indexes) {',
167+
expect.stringContaining('const __vite__fileDeps=['),
168168
])
169169
})
170170

0 commit comments

Comments
 (0)
Please sign in to comment.