简体   繁体   English

在 NextJS next.config.js 中对图像域使用正则表达式

[英]using regex for image domains in NextJS next.config.js

does regex work in next.config.js for image domains?正则表达式在 next.config.js 中是否适用于图像域? Looks like giphy uses different numbers for its endpoints (eg media0.giphy.com, media2.giphy.com) but regex isn't working so I'm getting this error: hostname "media0.giphy.com" is not configured under images in your next.config.js .看起来 giphy 为其端点使用了不同的数字(例如 media0.giphy.com、media2.giphy.com),但正则表达式不起作用,所以我收到此错误: hostname "media0.giphy.com" is not configured under images in your next.config.js If not, is there a good way to handle this?如果没有,有没有好的方法来处理这个问题?

next.config.js : next.config.js

const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
  images: {
    dangerouslyAllowSVG: true,
    domains: ["media\\d.giphy.com"],
  },
};

No, domains don't support regex.不, domains不支持正则表达式。 Use remotePatterns which support glob (similar to regex).使用支持 glob 的remotePatterns (类似于正则表达式)。

Domains

Similar to remotePatterns, the domains configuration can be used to provide a list of allowed hostnames for external images.与 remotePatterns 类似,域配置可用于为外部图像提供允许的主机名列表。

However, the domains configuration does not support wildcard pattern matching and it cannot restrict protocol, port, or pathname.但是,域配置不支持通配符模式匹配,它不能限制协议、端口或路径名。

Note: We recommend using remotePatterns instead so you can restrict protocol and pathname.注意:我们建议改用 remotePatterns,这样您就可以限制协议和路径名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在使用插件时为“next/image”添加域到 next.config.js - how to add domains to next.config.js for “next/image” while using a plugin NextJs-next.config.js-CSS加载器+自定义Webpack配置 - NextJs - next.config.js - CSS loader + custom Webpack config env 的 next.config.js 图像域问题 - next.config.js images domains problem with env TypeError:无法设置未定义的属性(设置“样式”)+在 next.config.js NextJS 中使用 withLess/withSass/withCSS - TypeError: Cannot set properties of undefined (setting 'styles') + Using withLess/withSass/withCSS in next.config.js NextJS 如何编写 next.config.js 文件 - How to compose the next.config.js file 在 next.config.js 中支持 ESM - Support ESM in next.config.js 在 next.config.js 中导出多个模块 - Export multiples modules in next.config.js Next.js 13 remotePatterns 的 next.config.js“端口”属性不适用于图像组件 - Next.js 13 next.config.js "port" attribute for remotePatterns doesn't work for Image component 通过 next.config.js 与使用 NEXT_PUBLIC 前缀在 nextjs 中公开环境变量有什么区别? - What's the difference between exposing environment variables in nextjs through the next.config.js vs with the NEXT_PUBLIC prefix? 使用 `@next/bundle-analyzer` 时在 `next.config.js` 中重定向? - Redirects in `next.config.js` while using `@next/bundle-analyzer`?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM