Open Extarys opened 3 months ago
Yeah, dynamic images are complicated. I managed to make it work more or less with this approach by providing addition query parameters.
const images = import.meta.glob('/src/**/*.{jpg,jpeg,png,gif,pdf}', {
eager: true,
query: {
enhanced: true,
w: '1280;640;400' // here you request the sizes you need
}
});
Or if you have a static import somewhere, you still need enhance it with similar query parameters to then use that object in the enhanced image:
<enhanced:img
src={imageSrc}
alt="woop woop"
sizes="(min-width:1920px) 1280px, (min-width:1080px) 640px, (min-width:768px) 400px"
/>
You can also run this on the generated bundle: https://github.com/divriots/jampack
Describe the bug
According to the documentation:
If you have a large image, such as a hero image taking the width of the design, you should specify sizes so that smaller versions are requested on smaller devices. E.g. if you have a 1280px image you may want to specify something like:
<enhanced:img src="./image.png" sizes="min(1280px, 100vw)"/>
If sizes is specified,
<enhanced:img>
will generate small images for smaller devices and populate the srcset attribute.This doesn't appear to work when the image is loaded dynamically:
Reproduction
Create a component (trimmed):
From a page:
Result:
Logs
System Info
Severity
annoyance
Additional Information
I hope this is how it is intended to be used, the docs seem to say so, but I'm quite a beginner at this.