Skip to content

Commit

Permalink
docs: more details for using import.meta.glob with enhanced-img
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed May 19, 2024
1 parent 119bff9 commit ec3caab
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions documentation/docs/40-best-practices/07-images.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,27 @@ You can also manually import an image asset and pass it to an `<enhanced:img>`.
import MyImage from './path/to/your/image.jpg?enhanced';
</script>

This comment has been minimized.

<enhanced:img src={MyImage} alt="Some alt text" />
<enhanced:img src={MyImage} alt="some alt text" />
```

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):

```js
const pictures = import.meta.glob(
'/path/to/assets/*.{avif,gif,heif,jpeg,jpg,png,tiff,webp}',
{
query: {
enhanced: true
```svelte
<script>
const imageModules = import.meta.glob(
'/path/to/assets/*.{avif,gif,heif,jpeg,jpg,png,tiff,webp,svg}',
{
eager: true,
query: {
enhanced: true
}
}
}
);
)
</script>
{#each Object.entries(imageModules) as [_path, module]}
<enhanced:img src={module.default} alt="some alt text" />
{/each}
```

### Intrinsic Dimensions
Expand Down

0 comments on commit ec3caab

Please sign in to comment.