Deploying React AppsEntry 8 of 11
Deploying to a Static Host
Uploading the build output to a host that serves static files, here Firebase Hosting (the course example).
Notes
- Any static host works: Firebase Hosting, Netlify, Vercel, Cloudflare Pages, GitHub Pages, AWS S3 + CloudFront.
- Firebase setup:
- Install the CLI:
npm install -g firebase-tools. firebase login.firebase init→ choose Hosting, select the project, set the public directory todist, answer Yes to "Configure as a single-page app," and No to overwritingindex.html.npm run build, thenfirebase deploy.
- Install the CLI:
firebase hosting:disabletakes the site offline.- Most hosts can also deploy automatically from a Git push.
What / Why / When
- What
Publishing the static files.
- Why
Static hosts are cheap or free, fast (CDN), and handle HTTPS.
- When
For client-rendered SPAs.
Code compare
npm install -g firebase-toolsfirebase loginfirebase init # Hosting, public dir: dist, single-page app: Yesnpm run buildfirebase deployThe same steps, with the public directory set to dist/<project>/browser. Alternatively, ng add @angular/fire adds an ng deploy command.
ng buildfirebase deployQuick reference
| Task | React | Angular |
|---|---|---|
| Public directory | dist | dist/<project>/browser |
| Deploy | firebase deploy | firebase deploy / ng deploy |