diff --git a/packages/vite/src/node/plugins/html.ts b/packages/vite/src/node/plugins/html.ts index e4b87807ac1cb6..f451a83833abd0 100644 --- a/packages/vite/src/node/plugins/html.ts +++ b/packages/vite/src/node/plugins/html.ts @@ -173,6 +173,9 @@ function traverseNodes( node: DefaultTreeAdapterMap['node'], visitor: (node: DefaultTreeAdapterMap['node']) => void, ) { + if (node.nodeName === 'template') { + node = (node as DefaultTreeAdapterMap['template']).content + } visitor(node) if ( nodeIsElement(node) || diff --git a/playground/assets/__tests__/assets.spec.ts b/playground/assets/__tests__/assets.spec.ts index ac5454229dde8e..5f2f6af6082763 100644 --- a/playground/assets/__tests__/assets.spec.ts +++ b/playground/assets/__tests__/assets.spec.ts @@ -588,3 +588,10 @@ test.runIf(isBuild)('assets inside +