From 8b4d79a38c59ebc2b8efc363e1931b697023a593 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Tue, 24 Dec 2024 18:23:31 +0800 Subject: [PATCH 1/3] fix: remove `vite-ignore` attribute error --- packages/vite/src/node/server/middlewares/indexHtml.ts | 2 +- playground/html/index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/server/middlewares/indexHtml.ts b/packages/vite/src/node/server/middlewares/indexHtml.ts index 228dce2ae7befa..7cae69dfb05d2f 100644 --- a/packages/vite/src/node/server/middlewares/indexHtml.ts +++ b/packages/vite/src/node/server/middlewares/indexHtml.ts @@ -268,7 +268,7 @@ const devHtmlHook: IndexHtmlTransformHook = async ( getScriptInfo(node) if (isIgnored) { - removeViteIgnoreAttr(s, sourceCodeLocation!) + removeViteIgnoreAttr(s, node.sourceCodeLocation!) } else if (src) { const processedUrl = processNodeUrl( src.value, diff --git a/playground/html/index.html b/playground/html/index.html index 431b02b6581541..3d72239d8e4a51 100644 --- a/playground/html/index.html +++ b/playground/html/index.html @@ -11,7 +11,7 @@

Hello

index.html (fallback)

External path:
- +
External path by rollupOptions.external (build only): From 157993c37a8be27155b52beefed56ed972ad8a50 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Tue, 24 Dec 2024 20:10:40 +0800 Subject: [PATCH 2/3] fix: update --- playground/html/index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/playground/html/index.html b/playground/html/index.html index 3d72239d8e4a51..37554e86e7cd76 100644 --- a/playground/html/index.html +++ b/playground/html/index.html @@ -11,6 +11,7 @@

Hello

index.html (fallback)

External path:
+
From f17912ee7d609758f477a4aadc53df6697e2ebbb Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Wed, 25 Dec 2024 10:21:01 +0800 Subject: [PATCH 3/3] fix: rename --- packages/vite/src/node/plugins/html.ts | 12 ++++++------ .../vite/src/node/server/middlewares/indexHtml.ts | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/vite/src/node/plugins/html.ts b/packages/vite/src/node/plugins/html.ts index 2e9b16668f36d6..cb9bf87192258d 100644 --- a/packages/vite/src/node/plugins/html.ts +++ b/packages/vite/src/node/plugins/html.ts @@ -199,13 +199,13 @@ export async function traverseHtml( export function getScriptInfo(node: DefaultTreeAdapterMap['element']): { src: Token.Attribute | undefined - sourceCodeLocation: Token.Location | undefined + srcSourceCodeLocation: Token.Location | undefined isModule: boolean isAsync: boolean isIgnored: boolean } { let src: Token.Attribute | undefined - let sourceCodeLocation: Token.Location | undefined + let srcSourceCodeLocation: Token.Location | undefined let isModule = false let isAsync = false let isIgnored = false @@ -214,7 +214,7 @@ export function getScriptInfo(node: DefaultTreeAdapterMap['element']): { if (p.name === 'src') { if (!src) { src = p - sourceCodeLocation = node.sourceCodeLocation?.attrs!['src'] + srcSourceCodeLocation = node.sourceCodeLocation?.attrs!['src'] } } else if (p.name === 'type' && p.value && p.value === 'module') { isModule = true @@ -224,7 +224,7 @@ export function getScriptInfo(node: DefaultTreeAdapterMap['element']): { isIgnored = true } } - return { src, sourceCodeLocation, isModule, isAsync, isIgnored } + return { src, srcSourceCodeLocation, isModule, isAsync, isIgnored } } const attrValueStartRE = /=\s*(.)/ @@ -447,7 +447,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin { // script tags if (node.nodeName === 'script') { - const { src, sourceCodeLocation, isModule, isAsync, isIgnored } = + const { src, srcSourceCodeLocation, isModule, isAsync, isIgnored } = getScriptInfo(node) if (isIgnored) { @@ -459,7 +459,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin { // referencing public dir url, prefix with base overwriteAttrValue( s, - sourceCodeLocation!, + srcSourceCodeLocation!, partialEncodeURIPath(toOutputPublicFilePath(url)), ) } diff --git a/packages/vite/src/node/server/middlewares/indexHtml.ts b/packages/vite/src/node/server/middlewares/indexHtml.ts index 7cae69dfb05d2f..4ab89bcc6f5ed2 100644 --- a/packages/vite/src/node/server/middlewares/indexHtml.ts +++ b/packages/vite/src/node/server/middlewares/indexHtml.ts @@ -264,7 +264,7 @@ const devHtmlHook: IndexHtmlTransformHook = async ( // script tags if (node.nodeName === 'script') { - const { src, sourceCodeLocation, isModule, isIgnored } = + const { src, srcSourceCodeLocation, isModule, isIgnored } = getScriptInfo(node) if (isIgnored) { @@ -280,7 +280,7 @@ const devHtmlHook: IndexHtmlTransformHook = async ( !isModule, ) if (processedUrl !== src.value) { - overwriteAttrValue(s, sourceCodeLocation!, processedUrl) + overwriteAttrValue(s, srcSourceCodeLocation!, processedUrl) } } else if (isModule && node.childNodes.length) { addInlineModule(node, 'js')