Deploy to Firebase Hosting with a CDN, set up rewrites for SPAs, and add Firebase Analytics.
{
"hosting": {
"public": "dist",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
],
"headers": [
{
"source": "**/*.@(js|css)",
"headers": [{"key": "Cache-Control", "value": "max-age=31536000"}]
}
]
}
}npm run build
firebase deploy --only hosting
# Live at your-app.web.appimport { getAnalytics, logEvent } from 'firebase/analytics';
const analytics = getAnalytics(app);
// Log custom events
logEvent(analytics, 'post_created', {
post_id: postId,
category: postCategory
});
logEvent(analytics, 'button_click', {
button_name: 'subscribe'
});
// Built-in: page_view, session_start, first_open tracked automatically** → /index.html), client-side routing works for all URLs. Without it, refreshing on /about returns a 404.** → /index.html rewrite is required for SPAs (React Router, Vue Router).