使用Nextjs时,预期结果是将Image组件呈现为.WebP或.AVIF格式,但它仍然是jpg格式。
以下是我的 next.config.js 文件。
以下是next/image组件:
有什么想法为什么它没有显示为avif/webp?我错过了什么吗?
/** @type {import('next').NextConfig} */
module.exports = {
images: {
domains: ['cdn.sanity.io'],
formats: ['image/avif', 'image/webp'],
},
reactStrictMode: true,
webpack(config) {
config.module.rules.push({
test: /\.svg$/,
use: [{ loader: '@svgr/webpack', options: { icon: true } }],
});
return config;
}, };
以下是next/image组件:
<Image
className="kitchen-img"
loader={myLoader}
loading="lazy"
layout="fill"
objectFit="cover"
src={urlFor(kitchen.mainImage).url()!}
alt={kitchen.title}
/>
有什么想法为什么它没有显示为avif/webp?我错过了什么吗?
const myLoader = ({ src, width, quality }: any) => {
return `${src}?w=${width}&q=${quality || 85}` };