Skip to content

Commit

Permalink
fix: inject __vite__mapDeps code before sourcemap file comment
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Jan 2, 2024
1 parent 8de7bd2 commit 0cd4f82
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/vite/src/node/plugins/importAnalysisBuild.ts
Expand Up @@ -634,13 +634,22 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
)
.join(',')}]`

s.append(`\
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 before sourcemap comment
const mapFileCommentMatch =
convertSourceMap.mapFileCommentRegex.exec(code)
if (mapFileCommentMatch) {
s.appendRight(mapFileCommentMatch.index, mapDepsCode)
} else {
s.append(mapDepsCode)
}

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

0 comments on commit 0cd4f82

Please sign in to comment.