How can I use enhanced:img with Vite import.glob.meta and typescript? #11438
Unanswered
keltonhalbert
asked this question in
Q&A
Replies: 1 comment 1 reply
-
I have a separate $lib file with these contents: type Image = {
sources: {
avif: string
webp: string
png: string
}
img: {
src: string
w: number
h: number
}
}
export const images = import.meta.glob<Image>('$lib/assets/images/*.{jpg,jpeg,png}', {
query: { enhanced: true },
import: 'default',
eager: true
}) Then I can import <enhanced:img src={images[path]} alt="alt" />. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm attempting to use
enhanced:img
with my project, ideally by using import.meta.glob to dynamically import my images from a folder, rather than hard-coding entries for each item as I update the page over time. This may be the wrong way to do it, but I wrote this+page.ts
loader for my route that appears to do what I want. However, the type ofmod
isPromise<unknown>
, making it really hard (or entirely unsuccessful at the moment) to properly type the data when passing it to some Svelte components.sveltePreprocess
in mysvelte.config.js
.I'm relatively new to Svelte/Sveltekit and fumbling in the dark, so any help is greatly appreciated :).
Beta Was this translation helpful? Give feedback.
All reactions