How to Publish a Static Website on Firebase

I know your girlfriend is awesome, but Firebase Hosting is even better because it's completely free.

Publish Static Website on Firebase

What if you don't have a girlfriend? To find a black hole, go to the nearest one.

Additionally, you can host your static website on Google's ultra-high-speed hosting.

Firebase is mostly utilized in Android programming for a variety of purposes, but we'll use it to host our static website. Maybe you're inventive.

What is Firebase Hosting and How Does It Differ From Other Hosting Services?

Firebase hosting is a fast, secure, and dependable dynamic and static web hosting service. Production-grade web content hosting for developers is what the big G calls it.

Furthermore, files are stored on SSDs and CDN edge servers all around the world. It can host files such as (JavaScript, HTML, CSS, and so on), which are likewise supported by Cloud Functions.

How to Publish a Static Website on Firebase

Keep in mind that you will need to take some measures that you have never taken before.

It may appear frightening at first, but once you've successfully deployed your static website, you'll be the happiest person alive.

Step 1: Create a Firebase account.

The first step is to create a free account at https://firebase.google.com/, which is self-explanatory.

Is it possible to eat pizza without putting it in your mouth?

After that, choose Go to Console, which requires a Google account.

What if you don't have a Google account? Then you're a baby who came on the article by accident.

Step 2 – Create a New Project.

Creating a project is essential since it allows you to preserve your data. Stick to the baby steps.
  • Select Add project from the drop-down menu.
  • Click Continue after entering your Project Name.
  • Click Continue after adding Google Analytics to your Firebase project. But, hold on, what exactly is Google Analytics? In basic terms, it's a free tool that may help you determine how many visitors your website receives over a period of time ranging from one day to ten years.
  • Select the checks for Analytics Location and Accept Terms, then click Create Project.
This will take a few seconds; in the meantime, call your cat and tell her to sing you a song (imagine if you don't have one).

After that, a notification will display stating that your project is complete, and you should click Continue.

Step 3 – Set Up Firebase Hosting

As indicated in the screenshot, go to the Develop section on the left side of the screen and choose Hosting.

When you get there, click Get Started.

(i) Install Firebase CLI

As you can see in the image, you'll need to install FirebaseTools on your PC. This is a Firebase command-line interface.

But what exactly is the Firebase CLI? The Firebase CLI is a command-line tool that lets you manage Firebase projects and do operations like Realtime Database administration from a terminal.

To do so, you'll need to use NPM (Node package manager).

To put it another way, you'll need NodeJS and NPM, both of which should be installed on your PC.

(a) Install NodeJs on your Computer

The first step is to get nodejs from nodejs.org if you don't already have it.

Don't be scared. Except for downloading and installing, you don't need to learn anything.

(b) Check whether NodeJs is installed

You may also check whether Node is installed on the command prompt if you're not sure. Simply enter “node -v” in cmd.

(c) Download and install the Firebase Tools

So, once you've installed Node on your PC, you're ready to go.

After that, you'll need another tool to install Firebase Tools using NPM, because NPM is included when you install Node.

Since "firebase-tools" is a package that you must install locally on your computer before you can use these tools to deploy your website to the backend, you can use it to install multiple packages.

So, "npm instal -g" means you're installing NPM globally on your computer, followed by “firebase-tools,” the package name. Now type the following code into the cmd prompt.

npm install -g firebase-tools

This will now install the package for you on your PC.

(d) Check Version Number

After the package has been installed, double-check that everything is in order. Simply copy and paste the code below into cmd and hit enter.

firebase -V

It’ll give you the Version Number.

You now have Firebase Tools installed locally on your computer, which you may utilize in the backend of your application.

Return to the Firebase Console window and press Next.

(ii) Initialize your project:

(a) Google Sign-In

Logging in is the next step for you to take. As a result, copy the code.

firebase login

And then paste it into the terminal window. Then type y.

The browser then displays a window. You must first log in.

After logging in, you'll notice that you've logged in both in the browser and the cmd prompt.

(b) Recommendation: Get the Visual Studio Editor

For the startup and deployment of the website, I'm using VisualStudio Editor. If you don't already have a Visual Studio Editor, you can get one from code.visualstudio.com and install it. Many developers that require a modern editor have found it to be a useful tool.

Darg the website folder on the Editor after installing the Visual Studio Editor, so it looks like this.

(c) Get started on your project

Select View -> Terminal from the top menu bar.

A terminal window emerges next. Make sure you're in the folder for the website.

Run the following command from the root directory of your app:

firebase init

If you get the same problem as in the image above, try running the command below. This is a temporary problem that you can fix. You can get around the ExecutionPolicy by using the command below. Copy the code below and paste it into the terminal window, then press Enter.

Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser

Then hit Enter after copying and pasting the instruction below.

firebase init

In the terminal window, you can see a good looking FIREBASE.
Following that, it will ask you if you are ready to proceed (y/n). Enter the letter y.

Then you'll notice a variety of services, but for this guide, you'll only be using hosting. Press the spacebar after using the arrow keys to travel down. After a small (*) appears, press Enter.

Then, using the arrow keys, select "Use an Existing Project" and press Enter.

The same firebase project is then displayed in the terminal window, as shown in the figure below. Choose your project and press Enter.

“Then”? (public) ” What are your intentions with regard to a public directory? Enter the code.

“Then”? Set up as a single-page app (all URLs should point to /index.html)? “ (y/N) Enter the letter N.

What is the reason for this?

Because this will only be used for a single page rewrite, you might be able to make something using react.

Then you'll see that Firebase has completed its initialization and inserted three files (“.firebasesrc“, “firebase.json“, and “.gitIgnore”).

As you can see, there is a public folder in the top left corner, and two files are located within the public folder,
  • 404.html: This file is used when your website is unavailable. If you like, you can make manual changes in the coding section.
  • index.html: This is a standard index page. You don't need to get rid of it.
Then drag and drop all of your files into a public folder, as shown in the figure below.

Because that is the folder that will be sent out.

When you deploy, it will take that public folder and upload it to the Firebase server, where you can view it online.

However, it is always a good idea to test locally on your PC before deploying to Firebase servers.

(iii) Check Project on Localhost

You may try this locally in the browser using the Firebase development tools, which include a local development server. To do so, type the following command in VisualStudio Editor's terminal window.

firebase serve

And it'll give you a local server URL, which you can ctrl+click to open the website in your browser.

In addition, the website is open in your browser locally. I realize it's a terrible website, but it's just a test.

(iv) Deploy Project To Firebase Server

Now that you've set up and tested your website locally, it's time to upload it to the Firebase server.

Now, from the top menu, select Terminal -> New Terminal to start a new Powershell window.

Then copy the cmd below and paste it into the editor's terminal window, then press Enter. This will start the deployment of your website.

firebase deploy

Your website has now been successfully deployed.

Open the URL for the hosting service. You can see the website has been successfully deployed with a secure connection by pressing ctrl+click.

Now go to the project console URL and use the console to manage your website. Now go to the deployed section and click on it.

It will then take you to the hosting dashboard. You can add a custom domain name, view your current files, add another site, and check your usage history all from this page.

It will then take you to the hosting dashboard. You can add a custom domain name, view your current files, add another site, and check your usage history all from this page.

firebase deploy

I modified the text in index.html, for example, and then re-deployed the code.

Then you'll notice that a new version with a new Id has been deployed.

If you need to update something on the server, keep this in mind. It will take some time for the server to change. It will not be updated immediately.

Post a Comment

Previous Post Next Post