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
yto “Configure a single-page app)? - answer
nto Set up automatic builds? - answer
nto the question about overwritingdist/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
