Deploy Angular app to Firebase Hosting
Developing an Angular application is pretty easy, But to deploy it somewhere for public use you should have a domain hosting/servers. If you don’t have any servers or domain then you can always deploy for free to some providers like Github Pages, Herokuapp, Firebase etc. In this article, I am going to cover how to deploy any Angular app to Firebase hosting.
Before we jump to steps make sure you have Node and npm is installed.
Step 1: Create a project in Firebase
To use firebase hosting first you need to create an account on firebase. Head toward https://console.firebase.google.com/ & login with your Google account. once you logged in you will be landed to this page, click on create a project.
Now you need to add a Project name & click Continue.
Once you added a project name, you will be landed to below page. If you wish to add a Google Analytics to your project then you can select the checkbox & click continue.
If you have checked the Google Analytics option then you will be asked for Configure Google Analytics. select your Analytics location & click on Create Project.
Yes! You have created your first project on Firebase.
Step 2: Initialize/Install Firebase-tools
Step: 2.1 Head over to your project folder & run below command.
npm install -g firebase-tools
-g will install firebase-tools globally to your machine, If you don't want to install it globally then you can remove -g & run the command.
Step: 2.2 To check firebase-tools is properly installed then run below command, this command will show you the version of firebase-tools installed on your machine.
Step: 2.3 Now you need to login to your firebase account, remember to login with the same Google account from which we have created a project in the previous step.
Step: 2.4 Once you logged in to Firebase, Now you need to initialize a Firebase project by running the below command.
Step: 2.5 Now you will be asked for some configurations questions.
Step: 2.6 Select Hosting option as we are hosting our application, you can select other options as well if you want to use firebase other services.
Step: 2.7 Next, you will be asked to create a new project or choose existing, select choose existing as we have already created a project on firebase console.
Step: 2.8 Next, You will be asked to select a project, you will be able to see the project name which you have created in the first step. select project name & click enter.
Step: 2.9 Next, you will be asked to select the public directory, Public directory is a directory in your project where your all the build files resided. Angular’s default URL for build files is dist/your-project-name/.
Step: 2.10 Next, you will be asked If your application in Single-page app, type Y as all angular app’s are single-page apps(basically firebase will redirect all the Sub URL’s to the index.html file).
Step: 2.11 Once you are done with all the steps you will see this screen.
Step: 2.12 Once the firebase init is done, Firebase will create a firebase.json file in your project directory. you can change the firebase configuration from this file also.
Now once you are done with the initialization process, Now build your angular application with below command. once your application is built you can see the build files in the “dist/your-project-name” directory of your application.
ng build --prod
Now it’s time to deploy your application to firebase with below command.
Bingo! you just deployed your first angular app to Firebase hosting.
Heads Up: I am working on one of the cool Chrome extensions which helps to format your code easily & it's superfast It can format your code within milliseconds. on top of it, it’s completely free for use. So go & hit that Add to Chrome Button. https://chrome.google.com/webstore/detail/code-formatter/njpgcnaadikbannefjibknjopmogeidm