Firebase

Preset: firebase (switch to this preset)

Nitro supports Firebase Hosting with Cloud Functions out of the box.

Note: You need to be on the Blaze plan to use Nitro with Cloud Functions.

If you don’t already have a firebase.json in your root directory, Nitro will create one the first time you run it. In this file, you will need to replace <your_project_id> with the ID of your Firebase project.

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>):

  1. {
  2. "projects": {
  3. "default": "<your_project_id>"
  4. }
  5. }

Then, just add Firebase dependencies to your project:

  1. # yarn
  2. yarn add --dev firebase-admin firebase-functions firebase-functions-test
  3. # npm
  4. npm install -D firebase-admin firebase-functions firebase-functions-test

Using Firebase CLI

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.

Install Firebase CLI globally

  1. # yarn
  2. yarn global add firebase-tools
  3. # npm
  4. npm install -g firebase-tools

Initialize your Firebase project

  1. firebase login
  2. firebase init hosting

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.

Once complete, add the following to your firebase.json to enable server rendering in Cloud Functions:

  1. {
  2. "functions": { "source": ".output/server" },
  3. "hosting": [
  4. {
  5. "site": "<your_project_id>",
  6. "public": ".output/public",
  7. "cleanUrls": true,
  8. "rewrites": [{ "source": "**", "function": "server" }]
  9. }
  10. ]
  11. }

You can find more details in the Firebase documentation.

Local preview

You can preview a local version of your site if you need to test things out without deploying.

  1. NITRO_PRESET=firebase yarn build
  2. firebase emulators:start

Deploy to Firebase Hosting via CLI

Deploying to Firebase Hosting is a simple matter of just running the firebase deploy command.

  1. NITRO_PRESET=firebase yarn build
  2. firebase deploy