images
如果你想使用云提供商来优化图片而不是使用 Next.js 内置图片优化 API,你可以使用以下内容配置 next.config.js
:
¥If you want to use a cloud provider to optimize images instead of using the Next.js built-in Image Optimization API, you can configure next.config.js
with the following:
此 loaderFile
必须指向相对于 Next.js 应用根目录的文件。该文件必须导出返回字符串的默认函数,例如:
¥This loaderFile
must point to a file relative to the root of your Next.js application. The file must export a default function that returns a string, for example:
或者,你可以使用 loader
属性 将函数传递给 next/image
的每个实例。
¥Alternatively, you can use the loader
prop to pass the function to each instance of next/image
.
需要了解:自定义接受函数的图片加载器文件,需要使用 客户端组件 来序列化提供的函数。
¥Good to know: Customizing the image loader file, which accepts a function, requires using Client Components to serialize the provided function.
要了解有关配置内置 图片优化 API 和 图片组件 行为的更多信息,请参阅 图片配置选项 了解可用选项。
¥To learn more about configuring the behavior of the built-in Image Optimization API and the Image Component, see Image Configuration Options for available options.
加载器配置示例
¥Example Loader Configuration
Akamai
AWS CloudFront
Cloudinary
Cloudflare
内容丰富
¥Contentful
快速
¥Fastly
Gumlet
ImageEngine
Imgix
PixelBin
Sanity
Sirv
Supabase
拇指
¥Thumbor