mirror of
https://github.com/vitejs/vite.git
synced 2024-11-22 07:09:05 +00:00
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>
This commit is contained in:
parent
b762517afc
commit
c0ec6bea69
@ -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('#!')) {
|
||||
|
@ -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=['),
|
||||
])
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user