Generate production www web app folder from the Ionic app
Use following command in existing ionic project to generate production web app www folder.
ionic capacitor build browser --prod
This will generate a www folder, which we need to publish to the Firebase hosting.
Prepare Firebase Hosting project to publish the web app
Install Firebase CLI
Install Firebase CLI globally, if not already installed.
npm install -g firebase-tools
Login to Firebase, through Firebase CLI
Login to Firebase through firebase CLI, using following command. This will open a login screen in browser window. Login there.
firebase login
Create Firebase hosting project
Create new directory for firebase hosting project
mkdir hosting
Switch to directory
cd hosting
Initialize Firebase hosting project
Enter following to initialize firebase hosting project.
firebase init
Choose Yes, to initialize the Firebase project
Choose following hosting feature from listed options:
Hosting: Configure files for Firebase Hosting and (optionally) set up GitHub Action deploys
Next selected Use an existing project, because in my case I had an existing project.
Then select your project from the list.
Next question is
What do you want to use as your public directory? (public)
type www
Next Question
Configure as a single-page app (rewrite all urls to /index.html)? (y/N)
Choose Y
Next question
Set up automatic builds and deploys with GitHub? No
Enter, and firebase initialization will complete.
In the hosting folder one www folder will be created.
Copy www folder to Firebase hosting project
In the hosting folder one www folder will be created.
Replace this folder with the www folder generated above from Ionic production web app build .
Publish the web app
Finally, enter following command to publish the web app.
firebase deploy
Web app will be published to firebase hosting and you will be presented with the published web app url.
Congrats! We successfully published web app from ionic project to the Firebase hosting.
Conclusion
In this post we learned how to publish an Ionic web project to Firebase hosting.
First we generated the www folder from the Ionic app. Then We created and prepared a new project for publishing to Firebase hosting. In the Firebase hosting project we copied the www folder from the Ionic app and then finally published to Firebase hosting using firebase deploy
In this blog post we will learn how to create a simple Notes application using Ionic 5 and Angular 12.
The Note application will be able to perform the read, create, update and delete operations, and Firestore database in the Firebase will be used as database.
For our Notes app we are going to save notes in the Firebase, and for that we need to create a new Firebase project. If you have existing Firebase project you can also use that.
Creating a Firebase project
To create a Firebase project head over to Firebase consoleand click on Add Project.
Firebase Console
Give your project a name, it’s Notes in my case.
You can change your project’s unique name here, although that doesn’t matters.
Project name
Enable Google Analytics to your project (optionally).
Enable Google Analytics
If you have chosen to enable Google Analytics then select or create the account for the Google Analytics.
Account for Google Analytics
In the following I have selected a new Google Analytics account.
New Google Analytics account
Then finally click on create project.
This will take a few minutes to setup the new Firebase project.
Setting up Firebase project.Firebase project setup done.
Click on continue.
and now we are inside the our brand new Firebase project.
Firebase project overview
Getting Firestore Database settings.
To store the Notes inside Firebase, we need some configuration settings from the Firebase project.
To get the settings, go to the Project settings.
Project settings option
Select the web app options from available platform options.
Web app option
Click on Register app.
App name
Copy the firebaseConfig from the next screen. We are going to need this in our Ionic app.
Then click on Continue to console at the bottom of the screen.
In the firebaseConfig one setting is missing in my case i.e. databaseURL.
The databaseURL specifies to which database data will be saved.
If this is missing in your case too, then add like following.
In this post we learned how to perform the CRUD operations in Firestore database inside Firebase using Ionic 5 application which was created using Angular 12.
We started with setting up the Firebase project to get firestore database settings. Then we created the ionic 5 application using ionic CLI and then added support for all of the Read, Create, Update and Delete operations.
Please leave your feedback or comment if you are facing any issue.