Firebase Hosting With React & Vite in 2023

Creating a starter React app, and hosting it on Firebase Hosting, is very simple. First you create the app using Vite’s React template. Then, you initialize Firebase Hosting in the project. Finally, you run it locally to develop, and deploy it to Firebase when ready for the world to see!

Create a React app named my-great-app:

$ npm create vite@latest my-great-app -- --template react
$ cd my-great-app
$ npm install
$ npm run build

Initialize Firebase Hosting:

$ firebase init hosting

  • select account
  • select “Use an existing project” (or create a new one if you prefer)
  • select your project
  • public directory should be dist
  • answer y to “Configure a single-page app)?
  • answer n to Set up automatic builds?
  • answer n to the question about overwriting dist/index.html

Edit firebase.json and add this line:

"predeploy": "npm run build",

right after this line:

"public": "dist",

and save the file.

Finally, run your app! To develop locally, run npm run dev, and to deploy to Firebase Hosting, run firebase deploy

Leave a Reply

Your email address will not be published. Required fields are marked *