将你的 Astro 网站部署到 Google 的 Firebase 托管
Firebase 托管 是 Google 的 Firebase 应用开发平台提供的一项服务,可用于部署 Astro 站点。
¥Firebase Hosting is a service provided by Google’s Firebase app development platform, which can be used to deploy an Astro site.
请参阅我们针对 添加 Firebase 后端服务 的单独指南,例如数据库、身份验证和存储。
¥See our separate guide for adding Firebase backend services such as databases, authentication, and storage.
项目配置
标题部分 项目配置¥Project Configuration
你的 Astro 项目可以作为静态站点或服务器端渲染站点(SSR)部署到 Firebase。
¥Your Astro project can be deployed to Firebase as a static site, or as a server-side rendered site (SSR).
静态站点
标题部分 静态站点¥Static Site
默认情况下,你的 Astro 项目是静态站点。你不需要任何额外的配置即可将静态 Astro 站点部署到 Firebase。
¥Your Astro project is a static site by default. You don’t need any extra configuration to deploy a static Astro site to Firebase.
SSR 适配器
标题部分 SSR 适配器¥Adapter for SSR
要在你的 Astro 项目中启用 SSR 并在 Firebase 上部署,请添加 Node.js 适配器。
¥To enable SSR in your Astro project and deploy on Firebase add the Node.js adapter.
如何部署
标题部分 如何部署¥How to deploy
-
Install the Firebase CLI. This is a command-line tool that allows you to interact with Firebase from the terminal.
终端窗口 npm install firebase-tools终端窗口 pnpm add firebase-tools终端窗口 yarn add firebase-tools -
Authenticate the Firebase CLI with your Google account. This will open a browser window where you can log in to your Google account.
终端窗口 npx firebase login终端窗口 pnpm exec firebase login终端窗口 yarn firebase login -
Enable experimental web frameworks support. This is an experimental feature that allows the Firebase CLI to detect and configure your deployment settings for Astro.
终端窗口 npx firebase experiments:enable webframeworks终端窗口 pnpm exec firebase experiments:enable webframeworks终端窗口 yarn firebase experiments:enable webframeworks -
Initialize Firebase Hosting in your project. This will create a
firebase.json
and.firebaserc
file in your project root.终端窗口 npx firebase init hosting终端窗口 pnpm exec firebase init hosting终端窗口 yarn firebase init hosting -
Deploy your site to Firebase Hosting. This will build your Astro site and deploy it to Firebase.
终端窗口 npx firebase deploy --only hosting终端窗口 pnpm exec firebase deploy --only hosting终端窗口 yarn firebase deploy --only hosting