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 f6ad1ed750c7f5..6e5578ce536e49 100644 --- a/playground/assets/__tests__/assets.spec.ts +++ b/playground/assets/__tests__/assets.spec.ts @@ -576,3 +576,10 @@ test.runIf(isBuild)('assets inside +