Skip to content

Commit

Permalink
fix(compiler-sfc): should transform non relative paths when base opti…
Browse files Browse the repository at this point in the history
…on is present

fix vitejs/vite-plugin-vue2#14
  • Loading branch information
yyx990803 committed Jun 28, 2022
1 parent bf64c4d commit 008d78b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 0 additions & 1 deletion packages/compiler-sfc/src/templateCompilerModules/utils.ts
Expand Up @@ -31,7 +31,6 @@ export function urlToRequire(
uriParts.path + (uriParts.hash || '')
)}"`
}
return returnValue
}

if (
Expand Down
6 changes: 5 additions & 1 deletion packages/compiler-sfc/test/compileTemplate.spec.ts
Expand Up @@ -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({
Expand All @@ -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', () => {
Expand Down

0 comments on commit 008d78b

Please sign in to comment.