Deploy Targets

Deploy targets are short-name identifiers (that you define yourself) for Firebase resources in your Firebase project, like a Hosting site with unique static assets or a group of Realtime Database instances that share the same security rules.

Deploy targets are useful when you have multiple Hosting sites, multiple Cloud Storage buckets, or multiple Realtime Database instances. With deploy targets, the Firebase CLI can deploy settings to a specific Firebase resource or group of resources in your project, such as:

  • The hosting configuration for each of your Hosting sites
  • Static assets from your project directory for each of your Hosting sites
  • Security rules shared by multiple Realtime Database instances or multiple Cloud Storage buckets

To set up a deploy target:

  1. Apply a target-name to the targeted Firebase resource or group of Firebase resources.
  2. In your firebase.json file, reference the associated target-name when you're configuring the settings for each resource or group of resources.

When you run Firebase CLI commands (like firebase deploy), the Firebase CLI pairs target-names with their associated Firebase resources. The CLI then communicates to your Firebase project the settings for each resource.

Set up deploy targets for your Firebase resources

Using the Firebase CLI, apply a target-name (short-name identifier that you define yourself) to a Firebase resource or group of Firebase resources. Firebase supports deploy targets for:

The settings for deploy targets are stored in the .firebaserc file in your project directory, so you only need to set up deploy targets one time per project.

Set up deploy targets for Hosting

To create a deploy target and apply a target-name to a Hosting site, run the following CLI command:

firebase target:apply type target-name resource-name

Where the parameters are:

  • type — the relevant Firebase resource type

    • For Firebase Hosting sites, use hosting.
  • target-name — a unique identifier for the Hosting site that you're deploying to

  • resource-name — the name of the Hosting site as listed in your Firebase project

For example, if you've created two sites (myapp-blog and myapp-app) in your Firebase project, you could apply a unique target-name to each site (blog and app, respectively) by running the following commands:

firebase target:apply hosting blog myapp-blog
firebase target:apply hosting app myapp-app

Set up deploy targets for Cloud Storage or Realtime Database

To create a deploy target and apply a target-name to Cloud Storage or Realtime Database resources, run the following CLI command:

firebase target:apply type target-name resource1-name resource2-name ...

Where the parameters are:

  • type — the relevant Firebase resource type

    • For Cloud Storage buckets, use storage.
    • For Realtime Database instances, use database.
  • target-name — a unique identifier for the resource or group of resources that share security rules

  • resource-name — the names of the resources as listed in your Firebase project (like storage bucket names or database instance names) that share security rules

For example, you could apply the target-name of main to a group of three regional Cloud Storage buckets (that share the same security rules) by running the following command:

firebase target:apply storage main myproject.appspot.com myproject-eu myproject-ja

Configure your firebase.json file to use deploy targets

After you've set up deploy targets for your Firebase resources, reference the applied target-names in your firebase.json configuration file:

  1. Create an array of configuration objects for each Firebase resource type (hosting, storage, or database).
  2. In the arrays, specify the target (using the target-name) and define your settings for the associated Firebase resource or group of resources.

Continuing the examples from above, where your Firebase project has two Hosting sites and three Cloud Storage buckets (that share the same security rules), your firebase.json file would look like this:

{
  "hosting": [ {
      "target": "blog", // "blog" is the applied target-name for the Hosting site myapp-blog.
      "public": "blog/dist"
    },
    {
      "target": "app", // "app" is the applied target-name for the Hosting site myapp-app
      "public": "app/dist",
      "rewrites": [...] // You can define specific hosting configurations for each site
    }
  ]
}

{
  "storage": [ {
      "target": "main", // "main" is the applied target-name for the group of Storage buckets
      "rules": "storage.main.rules" // The file that contains the shared security rules
    }
  ]
}

If you have multiple configurations for your resources, you can create multiple deploy targets and specify each one in the firebase.json file. All associated resources will be deployed together when you run firebase deploy.

Deploy to specific Firebase resources using deploy targets

Run any of the following commands from the root of your project directory.

Command Description
firebase deploy Creates a release of all deployable resources in your project directory
firebase deploy --only hosting:target-name Creates a release of only the resources for the specified Hosting target
firebase deploy --only storage:target-name Deploys only the rules file for the specified Cloud Storage target
firebase deploy --only database:target-name Deploys only the rules file for the specified Realtime Database target

Run either of the following commands to test your site locally before deploying to your Firebase project:

firebase serve
firebase serve --only hosting:target-name

Manage deploy targets

The settings for deploy targets are stored in the .firebaserc file in your project directory. You can manage your project's deploy targets by running any of the following commands from the root of your project directory.

Command Description
firebase target Lists the deploy targets for your current project directory
firebase target:remove type resource-name Removes a resource from the target to which it's been assigned
firebase target:clear type target-name Removes all the resources or Hosting site from the specified target

The remove and clear commands automatically update the deploy target settings in the .firebaserc file in your project directory.

Send feedback about...

Need help? Visit our support page.