diff --git a/packages/compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts b/packages/compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts index 91ea19dc..71be0e52 100644 --- a/packages/compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts +++ b/packages/compiler-sfc/__tests__/templateTransformAssetUrl.spec.ts @@ -79,4 +79,18 @@ describe('compiler sfc: transform asset url', () => { ) expect(code).toMatchSnapshot() }) + + // vitejs/vite#298 + test('should not transform hash fragments', () => { + const { code } = compileWithAssetUrls( + ` + + + + + ` + ) + // should not remove it + expect(code).toMatch(`"xlink:href": "#myCircle"`) + }) }) diff --git a/packages/compiler-sfc/src/templateTransformAssetUrl.ts b/packages/compiler-sfc/src/templateTransformAssetUrl.ts index 3ca2984e..a526d9a9 100644 --- a/packages/compiler-sfc/src/templateTransformAssetUrl.ts +++ b/packages/compiler-sfc/src/templateTransformAssetUrl.ts @@ -99,6 +99,7 @@ export const transformAssetUrl: NodeTransform = ( !assetAttrs.includes(attr.name) || !attr.value || isExternalUrl(attr.value.content) || + attr.value.content[0] === '#' || (!options.includeAbsolute && !isRelativeUrl(attr.value.content)) ) { return