【问题标题】:Creating NextJS app in an already initialised firebase project在已经初始化的 firebase 项目中创建 NextJS 应用程序
【发布时间】:2021-08-03 19:46:20
【问题描述】:

我正在尝试在 firebase 上使用 NextJS 托管我的网站。到目前为止,我获得的所有在线帮助都谈到了设置 NextJS 应用程序,然后初始化 Firebase 项目。问题是我已经为各种目的创建了 firebase 函数,并且已经有了一个静态托管的网站。我想知道如何使用 NextJS 项目替换我当前托管的静态网站。

【问题讨论】:

    标签: firebase next.js firebase-hosting


    【解决方案1】:

    您可以通过任何一种方式执行操作顺序,文件相互独立,只需要根据您的 Next.js 设置进行修改,即 SSR、SPA、静态等。

    关键说明是确保您在 firebase.json 文件中启用托管,并在需要时进行正确的重写。

    由于您使用的是静态生成,请确保托管路径指向您的构建文件夹,而不是默认的 "public",如果您正在生成 SPA,则需要重写 index.html 的所有路径

    片段示例:firebase.json

      "hosting": {
        "public": "dist/spa",
        "ignore": [
          "firebase.json",
          "**/.*",
          "**/node_modules/**"
        ],
        "rewrites": [
          {
            "source": "**",
            "destination": "/index.html"
          }
        ]
      }
    

    【讨论】:

      猜你喜欢
      • 2021-06-21
      • 1970-01-01
      • 2021-09-05
      • 2013-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-01
      相关资源
      最近更新 更多