Skip to content

Commit

Permalink
refactor(scan): use incremental scriptId for each html-like file
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverTsang committed Feb 20, 2022
1 parent 7d52fe8 commit d586af7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/vite/src/node/optimizer/scan.ts
Expand Up @@ -187,7 +187,6 @@ function esbuildScanPlugin(
name: 'vite:dep-scan',
setup(build) {
const scripts: Record<string, OnLoadResult> = {}
let scriptId = 0

// external urls
build.onResolve({ filter: externalRE }, ({ path }) => ({
Expand Down Expand Up @@ -233,7 +232,7 @@ function esbuildScanPlugin(
const regex = isHtml ? scriptModuleRE : scriptRE
regex.lastIndex = 0
let js = ''
let loader: Loader = 'js'
let scriptId = 0
let match: RegExpExecArray | null
while ((match = regex.exec(raw))) {
const [, openTag, content] = match
Expand All @@ -254,6 +253,7 @@ function esbuildScanPlugin(
) {
continue
}
let loader: Loader = 'js'
if (lang === 'ts' || lang === 'tsx' || lang === 'jsx') {
loader = lang
}
Expand Down Expand Up @@ -294,7 +294,7 @@ function esbuildScanPlugin(
}
}

js += `import ${JSON.stringify(virtualModulePrefix + key)};\n`
js += `import ${JSON.stringify(virtualModulePrefix + key)}\n`
}
}

Expand All @@ -307,7 +307,7 @@ function esbuildScanPlugin(
}

return {
loader,
loader: 'js',
contents: js
}
}
Expand Down

0 comments on commit d586af7

Please sign in to comment.