You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在已有next.config.js文件中配置next-images

如何合并next-images与现有Next.js配置?

你只需要将现有配置对象作为参数传入withImages函数,就能完成两者的配置合并,具体修改如下:

修改步骤

  • 在文件顶部添加next-images的引入语句
  • 将原有的nextConfig作为参数传入withImages(),替换原导出语句

修改后的完整代码

var fs = require('fs');
const withImages = require('next-images')

const nextConfig = {
    reactStrictMode: true,
    images: {
        remotePatterns: [
            {
                protocol: "http",
                hostname: "**",
            },
            {
                protocol: "https",
                hostname: "**",
            },
        ],
    },
    env: {
        customSnipcartJS: fs.readFileSync('public/file2.js').toString(),
        snipcartInstallJS: fs.readFileSync('public/file1.js').toString()
    }
}

module.exports = withImages(nextConfig)

这样修改后,Next.js会同时加载next-images的配置逻辑和你原本的自定义配置,满足业务需求。

内容的提问来源于stack exchange,提问作者Ayo Adesina

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 10:21:02