![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
vite-plugin-image-presets
Advanced tools
Image Presets for Vite.js apps. Optimize, resize, and process images consistently and with ease.
Image Presets for Vite.js apps
This Vite plugin allows you to define presets for image processing using Sharp, allowing you to optimize, resize, and process images consistently and with ease.
npm install -D vite-plugin-image-presets # pnpm, yarn
Add it to your plugins in vite.config.ts
import { defineConfig } from 'vite'
import imagePresets, { widthPreset } from 'vite-plugin-image-presets'
export default defineConfig({
plugins: [
imagePresets({
thumbnail: widthPreset({
class: 'img thumb',
loading: 'lazy',
widths: [48, 96],
formats: {
webp: { quality: 50 },
jpg: { quality: 70 },
},
}),
}),
],
})
Use the preset
query parameter to obtain an array of source
and img
attrs:
import thumbnails from '~/images/logo.jpg?preset=thumbnail'
expect(thumbnails).toEqual([
{
type: 'image/webp',
srcset: '/assets/logo.ffc730c4.webp 48w, /assets/logo.1f874174.webp 96w',
},
{
type: 'image/jpeg',
srcset: '/assets/logo.063759b1.jpeg 48w, /assets/logo.81d93491.jpeg 96w',
src: '/assets/logo.81d93491.jpeg',
class: 'img thumb',
loading: 'lazy',
},
])
You can also use the src
and srcset
query parameters for direct usage:
import srcset from '~/images/logo.jpg?preset=thumbnail&srcset'
import src from '~/images/logo.jpg?preset=thumbnail&src'
expect(srcset).toEqual('/assets/logo.063759b1.jpeg 48w, /assets/logo.81d93491.jpeg 96w')
expect(src).toEqual('/assets/logo.81d93491.jpeg')
Check the example for additional usage information and different preset examples, or see it live.
Additional usage documentation coming soon.
In the meantime, check the @islands/images
module for îles.
The hdPreset
is based on the following article by Jake Archibald:
This library is available as open source under the terms of the MIT License.
FAQs
Image Presets for Vite.js apps. Optimize, resize, and process images consistently and with ease.
We found that vite-plugin-image-presets demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.