Skip to content

Commit 966cabd

Browse files
authored
docs: more details for using import.meta.glob with enhanced-img (#12238)
1 parent cf99ac8 commit 966cabd

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

documentation/docs/40-best-practices/07-images.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,27 @@ You can also manually import an image asset and pass it to an `<enhanced:img>`.
7878
import MyImage from './path/to/your/image.jpg?enhanced';
7979
</script>
8080
81-
<enhanced:img src={MyImage} alt="Some alt text" />
81+
<enhanced:img src={MyImage} alt="some alt text" />
8282
```
8383

8484
You can also use [Vite's `import.meta.glob`](https://vitejs.dev/guide/features.html#glob-import). Note that you will have to specify `enhanced` via a [custom query](https://vitejs.dev/guide/features.html#custom-queries):
8585

86-
```js
87-
const pictures = import.meta.glob(
88-
'/path/to/assets/*.{avif,gif,heif,jpeg,jpg,png,tiff,webp}',
89-
{
90-
query: {
91-
enhanced: true
86+
```svelte
87+
<script>
88+
const imageModules = import.meta.glob(
89+
'/path/to/assets/*.{avif,gif,heif,jpeg,jpg,png,tiff,webp,svg}',
90+
{
91+
eager: true,
92+
query: {
93+
enhanced: true
94+
}
9295
}
93-
}
94-
);
96+
)
97+
</script>
98+
99+
{#each Object.entries(imageModules) as [_path, module]}
100+
<enhanced:img src={module.default} alt="some alt text" />
101+
{/each}
95102
```
96103

97104
### Intrinsic Dimensions

0 commit comments

Comments
 (0)