【问题标题】:how to add domains to next.config.js for "next/image" while using a plugin如何在使用插件时为“next/image”添加域到 next.config.js
【发布时间】:2021-06-27 23:52:35
【问题描述】:

这是我目前的设置。

// next.config.js
const withImages = require("next-images");

module.exports = withImages({
  webpack(config, options) {
    return config;
  },
});

我想添加此代码以允许来自域 localhost:3001 的图像。

images: {
  domains: ['localhost:3001'],
},

【问题讨论】:

    标签: javascript next.js nextjs-image


    【解决方案1】:

    我认为你应该设置assetPrefix,阅读docs中的选项

    // next.config.js
    const withImages = require('next-images')
    module.exports = withImages({
      assetPrefix: 'https://example.com',
      dynamicAssetPrefix: true,
      webpack(config, options) {
        return config
      }
    }
    

    【讨论】:

      【解决方案2】:

      您只需将images 对象添加到传递给withImages 的配置对象中。

      // next.config.js
      
      const withImages = require("next-images");
      
      module.exports = withImages({
          images: {
              domains: ['localhost:3001']
          },
          webpack(config, options) {
              return config;
          }
      });
      

      【讨论】:

        猜你喜欢
        • 2021-06-26
        • 2021-04-11
        • 2020-04-20
        • 2021-10-03
        • 2019-07-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多