小编Gra*_*lho的帖子

Next.js 配置文件中的 next/image 配置

I\xe2\x80\x99m 在我的 Headless 项目中实现 Next.js Image 组件。我\xe2\x80\x99m使用的CMS是WordPress。由于图像来自外部网站,我需要指定 上的域next.config.js,如文档指定:

\n

https://nextjs.org/docs/basic-features/image-optimization

\n
const nextConfig = {\n    image: {\n        domains: [\'https://example.com\'],\n    },\n}\n
Run Code Online (Sandbox Code Playgroud)\n

但在我的next.config.js文件 I\xe2\x80\x99ve 已经有这个配置:

\n
const withStyles = require(\'@webdeb/next-styles\');\n\nmodule.exports = withStyles({\n    sass: true,\n    modules: true,\n});\n
Run Code Online (Sandbox Code Playgroud)\n

所以我的努力​​是将这两者结合在配置文件中。

\n

仅对于某些上下文,没有图像配置,我遇到此错误:

\n
\n

错误: src 属性无效next/image,您的图像下未配置主机名next.config.js

\n
\n

在此输入图像描述

\n

我尝试使用以下代码将其组合在一起next-compose-plugins,但错误不断显示:

\n
const withStyles = require(\'@webdeb/next-styles\');\nconst withPlugins = require(\'next-compose-plugins\');\n\nconst nextConfig = {\n    image: {\n        domains: [\'https://example.com\'],\n    },\n}\n\nmodule.exports = withPlugins([\n    [withStyles({\n        sass: true,\n        modules: true,\n …
Run Code Online (Sandbox Code Playgroud)

wordpress reactjs next.js nextjs-image

6
推荐指数
1
解决办法
3万
查看次数

标签 统计

next.js ×1

nextjs-image ×1

reactjs ×1

wordpress ×1