代码之家  ›  专栏  ›  技术社区  ›  user3226932

在NextJS next.config.js中为图像域使用regex

  •  0
  • user3226932  · 技术社区  · 3 年前

    regex在next.config.js中适用于映像域吗?看起来giphy为其端点使用了不同的数字(例如media0.giphy.com、media2.giphy.com),但regex不起作用,所以我收到了以下错误: hostname "media0.giphy.com" is not configured under images in your next.config.js 。如果没有,有没有好的方法来处理这个问题?

    next.config.js :

    const nextConfig = {
      reactStrictMode: true,
      swcMinify: true,
      images: {
        dangerouslyAllowSVG: true,
        domains: ["media\\d.giphy.com"],
      },
    };
    
    
    1 回复  |  直到 3 年前
        1
  •  3
  •   Konrad    3 年前

    domains 不支持regex。使用 remotePatterns 支持glob(类似于regex)。

    Domains

    与remotePatterns类似,域配置可用于为外部映像提供允许的主机名列表。

    但是,域配置不支持通配符模式匹配,并且不能限制协议、端口或路径名。

    注意:我们建议使用remotePatterns,这样您就可以限制协议和路径名。