How to Deploy an Angular App to Firebase Hosting in 2021…
My fellow Angular wizards,
Why does it have to be SO hard to deploy your awesome Angular app to the cloud for others to admire?
If you’re like me, you’d rather focus on coding. Deploying should be something a toddler could do. But say…
…what are all these Firebase options about data storage, authentication, URL re-writes and distribution directory’s?
I thought coding was hard. Does deploying have to be harder?
Well… not any more code whiz! Let’s make you a deploying rock-star by following some simple steps to deploy a basic Hello World Angular website to Firebase Hosting.
Create Project in Firebase Console
Begin by going to the Firebase Console and click on “Add Project”.
Give it a name and click on continue.
Next choose if you want to use Google Analytics. The answer in your case is probably no.
And, last of all, wait for it to finish the setup.
Install and Configure Firebase
You can install Firebase by opening a terminal (or command prompt) and typing npm i firebase-tools -g
Let the command line whir and twirl awhile…. and… then once it’s done, run firebase login
to log into your Firebase account and get it set up.
Upload Angular Application
Open a terminal (or command prompt) and cd into the directory with your Angular app. In my case cd /home/daniel/Angular/hello-world
Next, build your Angular app by running ng build --prod
Once the build has finished we’ll run firebase init
to initialize the Firebase project. This will give us the ability to upload the production files created when we built the app.
Select the “Firebase Hosting” option by using your arrow keys and then hitting Enter.
Select the Firebase project that you created in the Firebase Console.
You will be asked to select your public directory. This is the directory where your built app was saved to. In my case, it’s dist/hello-world.
It will ask if you want to redirect all request’s to index.html. Be sure to select yes.
You’ll be asked if you want to overwrite index.html. Of course the answer is no!
And you are ready to deploy! 😀
Type firebase deploy
and give it some time to upload your files.
Bravo! You’re done!
If you enjoyed this article and found it useful please be sure to bang that 👏 button and follow me for more articles like this one.
Follow Me: GitHub, Medium, Personal Blog