DEV Community

Shun Yamada
Shun Yamada

Posted on

3 1

How to deploy a React application to Firebase Hosting

Firebase is awesome. You can build a functional application in React + Firebase soon. Here is a tutorial for deploying your React App to Firebase Hosting.

Install the Firebase CLI globally to your node modules:

$ npm install -g firebase-tools
Enter fullscreen mode Exit fullscreen mode

Next associate the Firebase CLI with a Firebase account:

$ firebase login
Enter fullscreen mode Exit fullscreen mode

And then, you have to connect Firebase hosting with your React app:

$ firebase init
Enter fullscreen mode Exit fullscreen mode

Choose the Hosting options.

Which Firebase CLI features do you want to set up for this folder? Press Space to select features, then Enter to confirm your choices.

$ Hosting
Enter fullscreen mode Exit fullscreen mode

Select a default Firebase project for this directory

$ <your-firebase-app-name>
Enter fullscreen mode Exit fullscreen mode

What do you want to use as your public directory?

$ public
Enter fullscreen mode Exit fullscreen mode

Configure as a single-page app (rewrite all urls to /index.html)?

$ Yes
Enter fullscreen mode Exit fullscreen mode

File public/index.html already exists. Overwrite?

$ No
Enter fullscreen mode Exit fullscreen mode

Done!

You have to update firebase.json like below:

{
  "hosting": {
    "public": "build",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}
Enter fullscreen mode Exit fullscreen mode

public should be build.

And you should delete .firebases folder every time you deploy.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay