Production Build Process
Cat Web uses Vite to create highly optimized production builds with TypeScript compilation, code splitting, and minification.Building the Application
Run TypeScript Compiler
The build process first type-checks your code:This executes:
tsc -b && vite buildTypeScript Build Info
TypeScript compiles in build mode (
-b flag), which:- Checks all type definitions
- Creates build info for incremental compilation
- Fails the build if type errors are found
- Stores build cache in
node_modules/.tmp/
The build command runs TypeScript compilation first. If type errors exist, the build will fail before Vite runs. This ensures type safety in production.
Build Output
After a successful build, thedist/ directory contains:
Build Optimizations
Vite automatically applies:- Code Splitting: Separates vendor dependencies and route-based chunks
- Tree Shaking: Removes unused code from the bundle
- Minification: Reduces file sizes using esbuild
- Asset Optimization: Compresses and optimizes images
- CSS Inlining: Critical CSS inlined in HTML
- Hash-based Caching: File names include content hashes for cache busting
Preview Production Build
Before deploying, test the production build locally:- Serves the
dist/folder on a local server (usuallyhttp://localhost:4173) - Simulates production environment behavior
- Allows testing with production optimizations enabled
TypeScript Compilation
Compiler Configuration
Cat Web uses multiple TypeScript configurations:tsconfig.json- Root config referencing other configstsconfig.app.json- Application source code settingstsconfig.node.json- Node.js tools and build scripts
Key Compiler Options
tsconfig.app.json
Build-Time Type Checking
Thetsc -b command:
- Performs incremental compilation using build info
- Checks all included TypeScript files
- Validates type definitions and imports
- Fails fast on type errors
- Faster than
tsc --noEmitfor large projects
Environment Variables in Production
Setting Production Variables
Environment variables must be set during the build process:Required Variables
Ensure these are set before building:.env.production
Variable Security
OnlyVITE_ prefixed variables are exposed to the client:
Never put sensitive secrets in VITE_ variables. They are visible in the compiled JavaScript bundle.
Deployment Considerations
Static File Hosting
Cat Web builds to static files that can be hosted on:- CDNs: Cloudflare Pages, Vercel, Netlify
- Cloud Storage: AWS S3 + CloudFront, Google Cloud Storage
- Web Servers: Nginx, Apache, Caddy
- Container Platforms: Docker with nginx base image
Server Configuration
For single-page applications (SPAs), configure your server to: Nginx Example:Docker Deployment
Dockerfile Example:Build Optimization Tips
Analyze Bundle Size
Use Vite’s build analysis:- Large vendor chunks (consider code splitting)
- Duplicate dependencies (check package.json)
- Oversized assets (compress images before importing)
Reduce Bundle Size
Optimize Images
Compress images before adding to
src/assets/. Consider using WebP format for better compression.Common Build Issues
TypeScript Errors
Problem: Build fails with type errors Solution:Out of Memory
Problem: Build fails with “JavaScript heap out of memory” Solution:Missing Environment Variables
Problem: Environment variables undefined in production Solution: Ensure variables are set before build, not at runtime. Rebuild after changing.env.production.
Build Scripts Reference
Continuous Integration
Example GitHub Actions workflow:.github/workflows/build.yml
Next Steps
Development
Return to development workflow
Configuration
Review configuration settings
