Add option to generate blurry placeholders #30
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi there, first of all thanks for this amazing vite plugin, I'm using it a bunch.
Context
I often found myself in the situation where I wanted to roll my own lazy loading using
IntersectionObserver
and show a blurry version of the image until the original image is loaded in.What this PR does
generateBlurryPlaceholder
option to the preset configurationgenerateBlurryPlaceholder
option will generate a 20px wide base64-inlined PNG of the image and add it to theplaceholder
key of the last item in the returned image arrayinferDimensions
option, which is also added to the last returned image, because this is likely the item that'll be used on theimg
tag in apicture
scenarioCaveats / Out of Scope
placeholder
as a key to the returnedImageAttrs
makes the object deviate from valid HTML image attributes, so you couldn’t simple prop-spread them into animg
tag. So we might want to find a better place to put the placeholder