Skip to content

Commit

Permalink
perf: reduce size of injected __vite__mapDeps code (#16184)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
4 people authored Apr 5, 2024
1 parent b762517 commit c0ec6be
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
8 changes: 1 addition & 7 deletions packages/vite/src/node/plugins/importAnalysisBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('#!')) {
Expand Down
4 changes: 2 additions & 2 deletions playground/js-sourcemap/__tests__/js-sourcemap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand All @@ -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=['),
])
})

Expand Down

0 comments on commit c0ec6be

Please sign in to comment.