fix(compiler-sfc): should transform non relative paths when base option is present

fix https://github.com/vitejs/vite-plugin-vue2/issues/14
This commit is contained in:
Evan You 2022-06-28 09:57:19 +08:00
parent bf64c4da5c
commit 008d78bd72
2 changed files with 5 additions and 2 deletions

View File

@ -31,7 +31,6 @@ export function urlToRequire(
uriParts.path + (uriParts.hash || '')
)}"`
}
return returnValue
}
if (

View File

@ -207,6 +207,7 @@ test('transform assetUrls and srcset with base option', () => {
<img src="~fixtures/logo.png">
<img src="~/fixtures/logo.png">
<img src="./logo.png" srcset="./logo.png 2x, ./logo.png 3x">
<img src="@/fixtures/logo.png">
</div>
`
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', () => {