Skip to content

Commit a788f39

Browse files
authored
docs(plugin-vue): clarify asset url handling (#8184)
1 parent bc740b8 commit a788f39

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

packages/plugin-vue/README.md

+35-8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,40 @@ export interface Options {
5151
}
5252
```
5353

54+
## Asset URL handling
55+
56+
When `@vitejs/plugin-vue` compiles the `<template>` blocks in SFCs, it also converts any encountered asset URLs into ESM imports.
57+
58+
For example, the following template snippet:
59+
60+
```vue
61+
<img src="../image.png" />
62+
```
63+
64+
Is the same as:
65+
66+
```vue
67+
<script setup>
68+
import _imports_0 from '../image.png'
69+
</script>
70+
71+
<img src="_imports_0" />
72+
```
73+
74+
By default the following tag/attribute combinations are transformed, and can be configured using the `template.transformAssetUrls` option.
75+
76+
```js
77+
{
78+
video: ['src', 'poster'],
79+
source: ['src'],
80+
img: ['src'],
81+
image: ['xlink:href', 'href'],
82+
use: ['xlink:href', 'href']
83+
}
84+
```
85+
86+
Note that only attribute values that are static strings are transformed. Otherwise, you'd need to import the asset manually, e.g. `import imgUrl from '../image.png'`.
87+
5488
## Example for passing options to `vue/compiler-sfc`:
5589

5690
```ts
@@ -64,14 +98,7 @@ export default {
6498
// ...
6599
},
66100
transformAssetUrls: {
67-
// default tags
68-
tags: {
69-
video: ['src', 'poster'],
70-
source: ['src'],
71-
img: ['src'],
72-
image: ['xlink:href', 'href'],
73-
use: ['xlink:href', 'href']
74-
}
101+
// ...
75102
}
76103
}
77104
})

0 commit comments

Comments
 (0)