【发布时间】: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
我将 nextjs 网络部署在非根目录中,例如 '/next' 而不是 '/'; 之后无法找到公共文件夹中的静态文件。 因为请求的 url 不是http://example.com/next/a.png 而是 http://example.com/a.png
如何配置它以使其请求'http://example.com/next/a.png' 请帮助我
【问题讨论】:
标签: next.js
您可以使用assetPrefix 功能来指定您的附加目录。
// next.config.js
module.exports = {
// Use the CDN in production and localhost for development.
assetPrefix: process.env.NODE_ENV === 'production' ? '/next/' : '',
}
【讨论】: