From c9fb79a40665d97e00ee89c0d968ae82a749861a Mon Sep 17 00:00:00 2001 From: Oliver Tsang <517578480@qq.com> Date: Mon, 21 Feb 2022 17:14:57 +0800 Subject: [PATCH] fix(scan): support named exports in vue/svelte files --- packages/vite/src/node/optimizer/scan.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/optimizer/scan.ts b/packages/vite/src/node/optimizer/scan.ts index 5532294de11edd..f52978d43736f9 100644 --- a/packages/vite/src/node/optimizer/scan.ts +++ b/packages/vite/src/node/optimizer/scan.ts @@ -147,6 +147,7 @@ export const commentRE = // const srcRE = /\bsrc\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/im const typeRE = /\btype\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/im const langRE = /\blang\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/im +const contextRE = /\bcontext\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/im function esbuildScanPlugin( config: ResolvedConfig, @@ -294,7 +295,23 @@ function esbuildScanPlugin( } } - js += `import ${JSON.stringify(virtualModulePrefix + key)}\n` + const virtualModulePath = JSON.stringify( + virtualModulePrefix + key + ) + + const contextMatch = openTag.match(contextRE) + const context = + contextMatch && + (contextMatch[1] || contextMatch[2] || contextMatch[3]) + + // Especially for Svelte files, exports in