Skip to content

Commit

Permalink
fix: preloadMarker end pos
Browse files Browse the repository at this point in the history
  • Loading branch information
pengbo43 committed Apr 30, 2024
1 parent bcab43c commit 0f0a1cf
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/vite/src/node/plugins/importAnalysisBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
const chunk = bundle[file]
// can't use chunk.dynamicImports.length here since some modules e.g.
// dynamic import to constant json may get inlined.
if (chunk.type === 'chunk' && preloadMarkerWithQuote.test(chunk.code)) {
if (chunk.type === 'chunk' && chunk.code.indexOf(preloadMarker) > -1) {
const code = chunk.code
let imports!: ImportSpecifier[]
try {
Expand Down Expand Up @@ -497,7 +497,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {

s.update(
markerStartPos,
markerStartPos + preloadMarker.length + 2,
markerStartPos + preloadMarker.length,
renderedDeps.length > 0
? `__vite__mapDeps([${renderedDeps.join(',')}])`
: `[]`,
Expand Down Expand Up @@ -531,14 +531,14 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
if (!rewroteMarkerStartPos.has(markerStartPos)) {
s.update(
markerStartPos,
markerStartPos + preloadMarker.length + 2,
markerStartPos + preloadMarker.length,
'void 0',
)
}
markerStartPos = indexOfMatchInSlice(
code,
preloadMarkerWithQuote,
markerStartPos + preloadMarker.length + 2,
markerStartPos + preloadMarker.length,
)
}

Expand Down

0 comments on commit 0f0a1cf

Please sign in to comment.