我是第一次尝试 Next.js。我已经建立了一个网站并尝试将其托管在 firebase 托管上。其他一切工作正常,但图像未在托管站点上呈现。 我的项目在根级别有文件夹 project 和 src 。 图像以 png 格式公开保存。它们在保存在 src/conatainers/homeContainer 和 src/conatainers/homeContainer 位置的页面中导入和使用。图像在本地服务器上正确呈现,但在托管站点上不起作用。
npm run build
不会在 next.js 中创建构建文件夹。
我正在运行以下代码来部署在 firebase 上。
firebase experiments:enable webframeworks
firebase init hosting
firebase deploy
Firebase 部署会在 build/static/media 文件夹中创建一个包含我的 png 的构建文件夹。 这似乎是由于 next.js 支持是 firebase 上的一项实验性功能。这个问题有解决办法吗?
我尝试将 next.config.js 文件修改为
const nextConfig = {
output: "export", // (optional) Set your desired output configuration
images: {
unoptimized: true,
},}
没成功。
Next js
output: "export",
在 out 目录中创建构建,而不是在构建文件夹中。
如果您希望 Next js 使用名称构建文件夹进行构建,您可以尝试这个,
const nextConfig = {
output: "export", // (optional) Set your desired output configuration
distDir:"build",
images: {
unoptimized: true,
},
}