How do you add Firebase to a web app?
Answer
Adding Firebase to a web app involves these steps: (1) Create project — go to the Firebase Console (console.firebase.google.com), create a project, and add a web app to get the config object; (2) Install SDK — npm install firebase; (3) Initialize — import and initialize with your config: import { initializeApp } from "firebase/app"; const app = initializeApp({ apiKey: "...", authDomain: "...", projectId: "...", ... }); (4) Import services — import only the services you need (tree-shaking): import { getFirestore } from "firebase/firestore"; import { getAuth } from "firebase/auth"; (5) Use services — const db = getFirestore(app); const auth = getAuth(app). Firebase SDK v9+ uses a modular API that supports tree-shaking, significantly reducing bundle size. Use the Firebase Emulator Suite for local development to avoid affecting production data.