From 008d78bd7280716d2d70e150e3ed2ac5ee8497f2 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 28 Jun 2022 09:57:19 +0800 Subject: [PATCH] fix(compiler-sfc): should transform non relative paths when base option is present fix https://github.com/vitejs/vite-plugin-vue2/issues/14 --- packages/compiler-sfc/src/templateCompilerModules/utils.ts | 1 - packages/compiler-sfc/test/compileTemplate.spec.ts | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/compiler-sfc/src/templateCompilerModules/utils.ts b/packages/compiler-sfc/src/templateCompilerModules/utils.ts index fa02fd2bdc..3e635b0020 100644 --- a/packages/compiler-sfc/src/templateCompilerModules/utils.ts +++ b/packages/compiler-sfc/src/templateCompilerModules/utils.ts @@ -31,7 +31,6 @@ export function urlToRequire( uriParts.path + (uriParts.hash || '') )}"` } - return returnValue } if ( diff --git a/packages/compiler-sfc/test/compileTemplate.spec.ts b/packages/compiler-sfc/test/compileTemplate.spec.ts index bba5d032dd..a405d644a4 100644 --- a/packages/compiler-sfc/test/compileTemplate.spec.ts +++ b/packages/compiler-sfc/test/compileTemplate.spec.ts @@ -207,6 +207,7 @@ test('transform assetUrls and srcset with base option', () => { + ` const result = compileTemplate({ @@ -218,13 +219,16 @@ test('transform assetUrls and srcset with base option', () => { expect(result.errors.length).toBe(0) - const vnode = mockRender(result.code) + const vnode = mockRender(result.code, { + '@/fixtures/logo.png': 'aliased' + }) expect(vnode.children[0].data.attrs.src).toBe('/base/logo.png') expect(vnode.children[2].data.attrs.src).toBe('/base/fixtures/logo.png') expect(vnode.children[4].data.attrs.src).toBe('/base/fixtures/logo.png') expect(vnode.children[6].data.attrs.srcset).toBe( '/base/logo.png 2x, /base/logo.png 3x' ) + expect(vnode.children[8].data.attrs.src).toBe('aliased') }) test('transform with includeAbsolute', () => {