First deployment
-
Open a terminal in the project folder.
Firebase creates its configuration files in the current folder, so run the following commands from the project root.
-
Install the Firebase CLI.
npm install -g firebase-tools -
Sign in and confirm access.
firebase login firebase projects:list -
Initialize Firebase Hosting.
firebase init hostingSelect the Firebase project, choose the public directory, and answer the remaining Hosting prompts. This creates or updates
firebase.jsonand.firebaserc. -
Deploy the site.
firebase deploy --only hosting
Hosting configuration
The public value controls which local folder Firebase
uploads. This project deploys the public folder:
{
"hosting": {
"target": "{choose any name}",
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
To change the target
Run the command from the project root. The first value is any target name you choose. The second value is the actual Hosting site ID shown in Firebase.
firebase target:apply hosting gautam-resume-website gautamsharma
firebase target:apply hosting {choose any name} {actual name of the website in Firebase}
Add the same name you chose as the target in
firebase.json:
{
"hosting": {
"target": "{choose any name}",
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
Firebase stores the target-to-site mapping in
.firebaserc.
Multiple Hosting sites
To deploy multiple sites from one Firebase project, create a
target for each site and change hosting to an array
in firebase.json:
{
"hosting": [
{
"target": "main-site",
"public": "public",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"]
},
{
"target": "resume-site",
"public": "resume",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"]
}
]
}
Deploy every configured Hosting site
firebase deploy --only hosting
Deploy one Hosting target
firebase deploy --only hosting:TARGET_NAME
There is no --all flag required for Hosting. The
--only hosting option deploys every Hosting entry in
the configuration.
Projects and folders
Add another Firebase project
Associate another Firebase project with the same local folder and give it an alias:
firebase use --add
Switch the active project
firebase use PROJECT_ID_OR_ALIAS
Deploy to an alias without switching
firebase deploy --only hosting --project PROJECT_ALIAS