【问题标题】:static file not found after deploy not in a root dir (nextjs)部署后未在根目录中找到静态文件(nextjs)
【发布时间】:2020-04-08 17:36:51
【问题描述】:

我将 nextjs 网络部署在非根目录中,例如 '/next' 而不是 '/'; 之后无法找到公共文件夹中的静态文件。 因为请求的 url 不是http://example.com/next/a.png 而是 http://example.com/a.png

如何配置它以使其请求'http://example.com/next/a.png' 请帮助我

【问题讨论】:

    标签: next.js


    【解决方案1】:

    您可以使用assetPrefix 功能来指定您的附加目录。

    // next.config.js
    
    module.exports = {
      // Use the CDN in production and localhost for development.
      assetPrefix: process.env.NODE_ENV === 'production' ? '/next/' : '',
    }
    

    【讨论】:

      猜你喜欢
      • 2023-03-25
      • 2022-11-01
      • 2021-09-12
      • 2021-03-24
      • 1970-01-01
      • 2016-03-11
      • 1970-01-01
      • 2022-07-29
      • 2020-11-04
      相关资源
      最近更新 更多