Gå til konsol

Test locally then deploy to your site

You can view and test your site locally, even emulate your HTTPS functions, before deploying your site to production.

Get started

Complete the steps listed on the Hosting Get Started page, which include installing the Firebase CLI and connecting your local project to your Firebase project.

Serve and test your Firebase project locally (optional)

You can view and test your Firebase project on locally hosted URLs before deploying to production. If you only want to test select features, you can use a comma-separated list in a flag on the firebase serve command.

Run the following command from the root of your local project directory if you want to either:

firebase serve --only hosting

Run any of the following commands from your project directory to emulate your project using local HTTP functions.

  • To emulate HTTP functions and hosting for testing on local URLs, use either of the following commands:

    firebase serve
    firebase serve --only functions,hosting // uses a flag
  • To emulate HTTP functions only, use the following command:

    firebase serve --only functions

By default, firebase serve only responds to requests from localhost. This means that you'll be able to access your hosted content from your computer's web browser but not from other devices on your network. If you'd like to test from other local devices, use the --host flag:

firebase serve --host 0.0.0.0  // accepts requests to any host

Deploy to your site

To deploy to your site, run the following command from the root of your local project directory:

firebase deploy

This command deploys a release to the following sites:

  • Your Firebase project's default Hosting sites, projectID.web.app and projectID.firebaseapp.com

  • Any custom domains that you've connected to your Hosting site.

You can optionally add a comment to a deploy. This comment will display with the other deployment information on your project's Hosting page. For example:

firebase deploy -m "Deploying the best new feature ever."

Deploys for projects with multiple sites

If you've added additional sites to your Firebase project, use the following command to deploy to one of those sites:

firebase deploy --only hosting:target-name

The target-name parameter is the unique identifier that you specified for the additional Hosting site during its setup.

Add predeploy and postdeploy scripted tasks

You can optionally connect shell scripts to the firebase deploy command to perform predeploy or postdeploy tasks. For example, a postdeploy hook could notify administrators of new site content deploys. Refer to the Firebase CLI documentation for more details.

Caching deployed content

When a request is made for static content, Firebase Hosting automatically caches the content on the CDN. If you redeploy your site's content, Firebase automatically clears all your cached static content across the CDN so that new requests receive your new content.

Note that you can configure the caching of dynamic content.

Serving over HTTPS

As you're developing your application, make sure that all external resources that are not hosted on Firebase Hosting are loaded over SSL (HTTPS), including any external scripts. Most browsers do not allow users to load "mixed content" (SSL and non-SSL traffic).

Manage deploys and versions

From your Firebase project's Hosting page, you can see a full history of your deploys. If you have multiple Hosting sites, click View for the desired site to see its deployment history.

Rollback deploys

To rollback to a previous deploy, hover over its entry in the list, click the three-dot overflow menu icon, then click Rollback.

Set limit for retained versions

Using a setting in the Firebase console, you can control how many of your site's past deployed versions are retained. The content of any versions over your set limit are scheduled for deletion, starting with the oldest versions first.

This setting can be helpful to control the level of storage maintained for your site. You can monitor your Hosting storage from your project's Hosting page, via Usage > Storage.

To set the limit for retained versions:

  1. In the Release History pane for your site, click the three-dot overflow menu for the table, then select Version history settings.

  2. Enter the number of versions that you'd like to retain, then click Save.