TaskFlow is feature-complete. In this challenge you will prepare it for production deployment. You will configure environment variables, tune the Vite build pipeline, and add hosting provider configuration files so the SPA works correctly on Vercel and Netlify.
- Expose environment-specific values through Vite's
VITE_env var convention - Use
import.meta.envto read those values at build time - Add type-safety for custom env vars via
ImportMetaEnvaugmentation - Configure Rollup manual chunks for predictable vendor splitting
- Enable production source maps for debuggability
- Write SPA fallback rules for Vercel (
vercel.json) and Netlify (netlify.toml/public/_redirects) - Understand the difference between dev server and production static hosting
Create .env.development and .env.production in the project root.
Both files must define:
VITE_API_URL=/api
All variables exposed to the browser must start with
VITE_. The dev server and the production build each load the appropriate file automatically.
In src/api/projects.ts and src/api/tasks.ts, replace every hardcoded
'/api' base path with:
const API_BASE = import.meta.env.VITE_API_URL || '/api';Open src/vite-env.d.ts and augment the ImportMetaEnv interface so
TypeScript knows about VITE_API_URL:
/// <reference types="vite/client" />
interface ImportMetaEnv {
readonly VITE_API_URL: string;
}
interface ImportMeta {
readonly env: ImportMetaEnv;
}Update vite.config.ts to add a build section:
- Enable
sourcemap: trueso production errors can be traced to source - Add
rollupOptions.output.manualChunksto split vendor code:vendor:react,react-domrouter:react-router,react-router-domquery:@tanstack/react-queryredux:@reduxjs/toolkit,react-redux
Create vercel.json:
{
"rewrites": [{ "source": "/(.*)", "destination": "/index.html" }]
}Create netlify.toml:
[build]
command = "npm run build"
publish = "dist"
[[redirects]]
from = "/*"
to = "/index.html"
status = 200Create public/_redirects as an alternative for Netlify:
/* /index.html 200
# Development (uses .env.development)
npm run dev
# Production build
npm run build
# Preview the production build locally
npm run preview
# Tests must still pass
npm testAfter npm run build, inspect the dist/assets/ directory. You should
see separate chunk files for vendor, router, query, and redux.
| Problem | Solution |
|---|---|
| Hardcoded URLs break staging/prod | Env vars swapped at build time |
| All code in one bundle → slow load | Manual chunks → parallel fetching |
| 404s on page refresh for SPA routes | Fallback rewrite to index.html |
| Unreadable prod stack traces | Source maps in dist/ |