diff --git a/packages/vite/src/node/optimizer/scan.ts b/packages/vite/src/node/optimizer/scan.ts index c47f38e18a8b32..33a0e83626a1bd 100644 --- a/packages/vite/src/node/optimizer/scan.ts +++ b/packages/vite/src/node/optimizer/scan.ts @@ -284,7 +284,9 @@ export const commentRE = //gs const srcRE = /\bsrc\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/i const typeRE = /\btype\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/i const langRE = /\blang\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/i -const contextRE = /\bcontext\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/i +const svelteScriptModuleRE = + /\bcontext\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/i +const svelteModuleRE = /\smodule\b/i function esbuildScanPlugin( config: ResolvedConfig, @@ -480,17 +482,28 @@ function esbuildScanPlugin( const virtualModulePath = JSON.stringify(virtualModulePrefix + key) - const contextMatch = contextRE.exec(openTag) - const context = - contextMatch && - (contextMatch[1] || contextMatch[2] || contextMatch[3]) + let addedImport = false - // Especially for Svelte files, exports in