Skip to content

Commit 008d78b

Browse files
committed
fix(compiler-sfc): should transform non relative paths when base option is present
fix vitejs/vite-plugin-vue2#14
1 parent bf64c4d commit 008d78b

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

packages/compiler-sfc/src/templateCompilerModules/utils.ts

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export function urlToRequire(
3131
uriParts.path + (uriParts.hash || '')
3232
)}"`
3333
}
34-
return returnValue
3534
}
3635

3736
if (

packages/compiler-sfc/test/compileTemplate.spec.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ test('transform assetUrls and srcset with base option', () => {
207207
<img src="~fixtures/logo.png">
208208
<img src="~/fixtures/logo.png">
209209
<img src="./logo.png" srcset="./logo.png 2x, ./logo.png 3x">
210+
<img src="@/fixtures/logo.png">
210211
</div>
211212
`
212213
const result = compileTemplate({
@@ -218,13 +219,16 @@ test('transform assetUrls and srcset with base option', () => {
218219

219220
expect(result.errors.length).toBe(0)
220221

221-
const vnode = mockRender(result.code)
222+
const vnode = mockRender(result.code, {
223+
'@/fixtures/logo.png': 'aliased'
224+
})
222225
expect(vnode.children[0].data.attrs.src).toBe('/base/logo.png')
223226
expect(vnode.children[2].data.attrs.src).toBe('/base/fixtures/logo.png')
224227
expect(vnode.children[4].data.attrs.src).toBe('/base/fixtures/logo.png')
225228
expect(vnode.children[6].data.attrs.srcset).toBe(
226229
'/base/logo.png 2x, /base/logo.png 3x'
227230
)
231+
expect(vnode.children[8].data.attrs.src).toBe('aliased')
228232
})
229233

230234
test('transform with includeAbsolute', () => {

0 commit comments

Comments
 (0)