payload-webp
payloadcms/payload plugin for automatic image conversion to webp format.
Getting started
- Install the package with
npm i payload-webp
OR yarn add payload-webp
- Import the plugin to your
payload.config.ts
:
import webp from "payload-webp";
export default buildConfig({
...
plugins: [
webp(webpPluginOptions)
]
)};
- After uploading images to your upload-enabled collection new field called webp is added with converted image => webp file meteadata and its sizes.
Access webp field with graphql like so:
query {
allMedia {
docs {
url
filesize
webp {
url
filesize
sizes {
thumbnail {
width
height
url
}
}
}
}
}
}
By default webp images are being processed to reduce their filesize as well.
Plugin options
Optionally you can pass JSON with following plugin options to tweak compression or limit conversion to particular mimeTypes or specific upload-enabled collections.
interface WebpPluginOptions {
mimeTypes?: string[];
sharpWebpOptions?: sharp.WebpOptions;
collections?: CollectionConfig['slug'][];
sync?: boolean;
}