GET STARTING WITH FIREBASE HOSTING
Get started with Firebase Hosting
Before you begin
Before you can set up Firebase Hosting, you need to create a Firebase project.
Step 1: Install the Firebase CLI
- Install Node.js using one of the following options. Installing Node.js automatically installs npm.
- For Mac/Linux, use
nvm
(the Node Version Manager). - For Windows, use
nvm-windows
.
- For Mac/Linux, use
- Install the Firebase CLI using npm by running:This command installs the globally available
firebase
command. To update to the latest version of the Firebase CLI, re-run the samenpm install
command. - Sign into Firebase using your Google account by running:This command connects your local machine to Firebase and grants you access to your Firebase projects.
- To test that authentication worked (and to list all of your Firebase projects), run the following command:The displayed list should be the same as the Firebase projects listed in the Firebase console.
Update to the latest CLI version
Make sure that you're using the most up-to-date Firebase CLI version by re-running the CLI installation command:
Step 2: Initialize your project
To connect your local project to your Firebase project, run the following command from the root of your local project directory:
During project initialization, from the Firebase CLI prompts:
- Select to set up
Hosting
.If you want to set up other Firebase products for your project, refer to their documentation for setup information. Note that you can always runfirebase init
later to set up more Firebase products. - Select a Firebase project to connect to your local project directory.The selected Firebase project is your "default" Firebase project for your local project directory. To connect additional Firebase projects to your local project directory, set up project aliases.
- Specify a directory to use as your public root directory.This directory contains all your publicly served static files, including your
index.html
file and any other assets that you want to deploy to Firebase Hosting.- The default for the public root directory is called
public
.- You can specify your public root directory now or you can specify it later in your
firebase.json
configuration file. - If you select the default and don't already have a directory called
public
, Firebase creates it for you.
- If you don't already have a valid
index.html
file or404.html
file in your public root directory, Firebase creates them for you.
- Choose a configuration for your site.If you select to make a one-page app, then Firebase automatically adds rewrite configurations for you.
At the end of initialization, Firebase automatically creates and adds two files to the root of your local app directory:
- A
firebase.json
configuration file that lists your project configuration. Learn more about this file on theconfigure hosting behavior page.
Step 3: Deploy to your site
To deploy to your site, run the following command from the root of your local project directory:
This command deploys a release to your Firebase project's default Hosting sites:
projectID.web.app
projectID.firebaseapp.com
Learn more about deploys and even locally testing your site.
Next steps
Now your site is ready to share with the world! You can also learn how to:
Also, take a look at the full documentation for the Firebase CLI.
Comments
Post a Comment