2021-10-11 16:35:02 +00:00
---
icon: LogoFirebase
---
2021-06-14 12:31:30 +00:00
# Firebase Hosting
2021-10-11 16:35:02 +00:00
How to deploy Nuxt to Firebase Hosting.
::list
2021-10-29 11:26:01 +00:00
2021-10-11 16:35:02 +00:00
- Support for serverless build
- Minimal configuration required
::
2021-06-14 12:31:30 +00:00
## Setup
2021-10-11 17:18:38 +00:00
Nitro supports [Firebase Hosting ](https://firebase.google.com/docs/hosting ) with Cloud Functions out of the box.
2021-06-14 12:31:30 +00:00
2021-11-21 12:31:44 +00:00
**Note**: You will need to be on the **Blaze plan** to use Nitro with Cloud Functions.
2021-06-14 12:31:30 +00:00
### Using Nitro
If you don't already have a `firebase.json` in your root directory, Nitro will create one the first time you run it. All you will need to do is edit this to replace `<your_project_id>` with the project ID that you have chosen on Firebase.
2021-10-29 08:29:54 +00:00
This file should then be committed to version control. You can also create a `.firebaserc` file if you don't want to manually pass your project ID to your `firebase` commands (with `--project <your_project_id>` ):
2021-10-29 11:26:01 +00:00
2021-06-14 12:31:30 +00:00
```json [.firebaserc]
{
"projects": {
"default": "< your_project_id > "
}
}
```
Then, just add Firebase dependencies to your project:
2021-10-11 17:18:38 +00:00
::code-group
2021-10-29 11:26:01 +00:00
2021-10-11 17:18:38 +00:00
```bash [Yarn]
2021-06-14 12:31:30 +00:00
yarn add --dev firebase-admin firebase-functions firebase-functions-test
```
2021-10-29 11:26:01 +00:00
2021-10-11 17:18:38 +00:00
```bash [NPM]
npm install -D firebase-admin firebase-functions firebase-functions-test
```
2021-10-29 11:26:01 +00:00
2021-10-11 17:18:38 +00:00
::
2021-06-14 12:31:30 +00:00
### Using Firebase CLI
2021-11-21 12:31:44 +00:00
You may instead prefer to set up your project with the Firebase CLI, which will fetch your project ID for you, add required dependencies (see above) and even set up automated deployments via GitHub Actions.
2021-06-14 12:31:30 +00:00
2021-11-21 12:31:44 +00:00
#### Install Firebase CLI globally
2021-10-11 17:18:38 +00:00
::code-group
2021-10-29 11:26:01 +00:00
2021-10-11 17:18:38 +00:00
```bash [Yarn]
2021-10-24 18:12:05 +00:00
yarn global add firebase-tools
2021-10-11 17:18:38 +00:00
```
2021-10-29 11:26:01 +00:00
2021-10-11 17:18:38 +00:00
```bash [NPM]
npm install -g firebase-tools
```
2021-10-29 11:26:01 +00:00
2021-10-11 17:18:38 +00:00
::
2021-11-21 12:31:44 +00:00
#### Initialize your Firebase project
2021-10-11 17:18:38 +00:00
```bash
2021-06-14 12:31:30 +00:00
firebase login
firebase init hosting
```
2021-11-21 12:31:44 +00:00
When prompted, you can enter `.output/public` as the public directory. In the next step, **do not** configure your project as a single-page app.
2021-06-14 12:31:30 +00:00
Once complete, add the following to your `firebase.json` to enable server rendering in Cloud Functions:
2021-10-29 11:26:01 +00:00
2021-06-14 12:31:30 +00:00
```json [firebase.json]
{
"functions": { "source": ".output/server" },
"hosting": [
{
"site": "< your_project_id > ",
"public": ".output/public",
"cleanUrls": true,
"rewrites": [{ "source": "**", "function": "server" }]
}
]
}
```
You can find more details in the [Firebase documentation ](https://firebase.google.com/docs/hosting/quickstart ).
## Local preview
You can preview a local version of your site if you need to test things out without deploying.
```bash
NITRO_PRESET=firebase yarn build
firebase emulators:start
```
## Deploy to Firebase Hosting via CLI
Deploying to Firebase Hosting is a simple matter of just running the `firebase deploy` command.
```bash
NITRO_PRESET=firebase yarn build
firebase deploy
```
## Demo site
2021-11-21 12:31:44 +00:00
A live demo is available on < https: / / nitro-demo-dfabe . web . app > .