Skip to content

Commit

Permalink
docs(assets): add note to inlining SVG through url() (#15534)
Browse files Browse the repository at this point in the history
Co-authored-by: 翠 / green <green@sapphi.red>
  • Loading branch information
chaejunlee and sapphi-red committed Mar 3, 2024
1 parent 11cceea commit 0c0aeae
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/guide/assets.md
Expand Up @@ -30,6 +30,16 @@ The behavior is similar to webpack's `file-loader`. The difference is that the i

- TypeScript, by default, does not recognize static asset imports as valid modules. To fix this, include [`vite/client`](./features#client-types).

::: tip Inlining SVGs through `url()`
When passing a URL of SVG to a manually constructed `url()` by JS, the variable should be wrapped within double quotes.

```js
import imgUrl from './img.svg'
document.getElementById('hero-img').style.background = `url("${imgUrl}")`
```

:::

### Explicit URL Imports

Assets that are not included in the internal list or in `assetsInclude`, can be explicitly imported as a URL using the `?url` suffix. This is useful, for example, to import [Houdini Paint Worklets](https://houdini.how/usage).
Expand Down

0 comments on commit 0c0aeae

Please sign in to comment.