Skip to content

Commit

Permalink
fix: remove unnecessary __vite__mapDeps
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Mar 26, 2024
1 parent cdc664d commit 1d96f2a
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions packages/vite/src/node/plugins/importAnalysisBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,32 +498,36 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
s.update(
markerStartPos,
markerStartPos + preloadMarker.length + 2,
`__vite__mapDeps([${renderedDeps.join(',')}])`,
renderedDeps.length > 0
? `__vite__mapDeps([${renderedDeps.join(',')}])`
: `[]`,
)
rewroteMarkerStartPos.add(markerStartPos)
}
}
}

const fileDepsCode = `[${fileDeps
.map((fileDep) =>
fileDep.runtime ? fileDep.url : JSON.stringify(fileDep.url),
)
.join(',')}]`

const mapDepsCode = `\
function __vite__mapDeps(indexes) {
if (!__vite__mapDeps.viteFileDeps) {
__vite__mapDeps.viteFileDeps = ${fileDepsCode}
}
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
}\n`

// inject extra code at the top or next line of hashbang
if (code.startsWith('#!')) {
s.prependLeft(code.indexOf('\n') + 1, mapDepsCode)
} else {
s.prepend(mapDepsCode)
if (fileDeps.length > 0) {
const fileDepsCode = `[${fileDeps
.map((fileDep) =>
fileDep.runtime ? fileDep.url : JSON.stringify(fileDep.url),
)
.join(',')}]`

const mapDepsCode = `\
function __vite__mapDeps(indexes) {
if (!__vite__mapDeps.viteFileDeps) {
__vite__mapDeps.viteFileDeps = ${fileDepsCode}
}
return indexes.map((i) => __vite__mapDeps.viteFileDeps[i])
}\n`

// inject extra code at the top or next line of hashbang
if (code.startsWith('#!')) {
s.prependLeft(code.indexOf('\n') + 1, mapDepsCode)
} else {
s.prepend(mapDepsCode)
}
}

// there may still be markers due to inlined dynamic imports, remove
Expand Down

0 comments on commit 1d96f2a

Please sign in to comment.