8000 refactor(build): remove quotes from preload marker (#16562) · vitejs/vite@9853190 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9853190

Browse files
PengBoUESTCpengbo43
and
pengbo43
authored
refactor(build): remove quotes from preload marker (#16562)
Co-authored-by: pengbo43 <pengbo43@jd.com>
1 parent 4102ca9 commit 9853190

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

packages/vite/src/node/plugins/importAnalysisBuild.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const preloadMarker = `__VITE_PRELOAD__`
3737
export const preloadBaseMarker = `__VITE_PRELOAD_BASE__`
3838

3939
export const preloadHelperId = '\0vite/preload-helper.js'
40-
const preloadMarkerWithQuote = new RegExp(`['"]${preloadMarker}['"]`, 'g')
40+
const preloadMarkerRE = new RegExp(preloadMarker, 'g')
4141

4242
const dynamicImportPrefixRE = /import\s*\(/
4343

@@ -268,7 +268,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
268268
str().prependLeft(expStart, `${preloadMethod}(() => `)
269269
str().appendRight(
270270
expEnd,
271-
`,${isModernFlag}?"${preloadMarker}":void 0${
271+
`,${isModernFlag}?${preloadMarker}:void 0${
272272
optimizeModulePreloadRelativePaths || customModulePreloadPaths
273273
? ',import.meta.url'
274274
: ''
@@ -427,15 +427,12 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
427427

428428
let markerStartPos = indexOfMatchInSlice(
429429
code,
430-
preloadMarkerWithQuote,
430+
preloadMarkerRE,
431431
end,
432432
)
433433
// fix issue #3051
434434
if (markerStartPos === -1 && imports.length === 1) {
435-
markerStartPos = indexOfMatchInSlice(
436-
code,
437-
preloadMarkerWithQuote,
438-
)
435+
markerStartPos = indexOfMatchInSlice(code, preloadMarkerRE)
439436
}
440437

441438
if (markerStartPos > 0) {
@@ -505,7 +502,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
505502

506503
s.update(
507504
markerStartPos,
508-
markerStartPos + preloadMarker.length + 2,
505+
markerStartPos + preloadMarker.length,
509506
renderedDeps.length > 0
510507
? `__vite__mapDeps([${renderedDeps.join(',')}])`
511508
: `[]`,
@@ -534,19 +531,19 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
534531

535532
// there may still be markers due to inlined dynamic imports, remove
536533
// all the markers regardless
537-
let markerStartPos = indexOfMatchInSlice(code, preloadMarkerWithQuote)
534+
let markerStartPos = indexOfMatchInSlice(code, preloadMarkerRE)
538535
while (markerStartPos >= 0) {
539536
if (!rewroteMarkerStartPos.has(markerStartPos)) {
540537
s.update(
541538
markerStartPos,
542-
markerStartPos + preloadMarker.length + 2,
539+
markerStartPos + preloadMarker.length,
543540
'void 0',
544541
)
545542
}
546543
markerStartPos = indexOfMatchInSlice(
547544
code,
548-
preloadMarkerWithQuote,
549-
markerStartPos + preloadMarker.length + 2,
545+
preloadMarkerRE,
546+
markerStartPos + preloadMarker.length,
550547
)
551548
}
552549

0 commit comments

Comments
 (0)
0