Skip to content

Commit 466c476

Browse files
committed
docs(faq): update entry about relative asset urls
1 parent b1ad992 commit 466c476

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

docs/faq.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,16 @@ See the faq about [vite and prebundling](#what-is-going-on-with-vite-and-pre-bun
238238
>
239239
> For backwards compatibility, you can keep the `svelte` field in addition to the `exports` condition. But make sure that both always resolve to the same files.
240240
241-
### How do I manually specify an `<img/>` `src`, or any other asset, with an inline URL?
241+
### How can I use relative paths for asset references in svelte components like `<img src="./asset.png">`
242242

243-
Currently, Svelte does not support inline asset URLs, you can only specify it via an imported asset, meaning that the following won't work:
243+
This is not supported out of the box. To resolve assets, you have to either import them like this:
244244

245-
```
246-
<img src="./assets/inline/url/to/asset.png" />
245+
```html
246+
<script>
247+
import assetUrl from './asset.png';
248+
</script>
249+
<img src="{assetUrl}" />
247250
```
248251

249-
2 recommended solutions are to use either [sveltejs/enhanced-img](https://kit.svelte.dev/docs/images#sveltejs-enhanced-img) (only for image elements) or [svelte-preprocess-import-assets](https://www.npmjs.com/package/svelte-preprocess-import-assets) (for all asset URLs).
252+
or use a separate tool to add this functionality.
253+
The 2 recommended solutions are [sveltejs/enhanced-img](https://kit.svelte.dev/docs/images#sveltejs-enhanced-img) (only for image elements) and [svelte-preprocess-import-assets](https://www.npmjs.com/package/svelte-preprocess-import-assets) (for all asset URLs).

0 commit comments

Comments
 (0)