Build Overview
Exchange Web uses a two-stage build process that combines TypeScript compilation with Vite’s production bundler for optimal performance.Running the Build
Build from root (Recommended)
From the root directory, use Turborepo to build all packages:This command runs
turbo build, which:- Builds packages in dependency order
- Leverages Turborepo’s caching for faster builds
- Only rebuilds changed packages
Build Process
The build process for the web app (apps/web/package.json) runs:
Stage 1: TypeScript Compilation
Stage 2: Vite Production Build
Build Configuration
The build is configured inapps/web/vite.config.ts:
Output Directory
After a successful build, production files are output to:The
dist directory contains everything needed to deploy your application. All files are optimized and ready for production.Build Optimization
Vite automatically applies several optimizations:Code Splitting
- Automatic route-based code splitting via React Router
- Dynamic imports create separate chunks
- Reduces initial bundle size
Asset Optimization
- Images and assets are hashed for cache busting
- Small assets are inlined as base64
- Font files are optimized
Minification
- JavaScript minified with esbuild (extremely fast)
- CSS minified and optimized
- HTML minified
Tree Shaking
- Unused code is automatically removed
- ES modules enable efficient tree shaking
- Reduces final bundle size
Turborepo Build Caching
Turborepo caches build outputs for faster subsequent builds:- dependsOn: Ensures dependencies build first
- inputs: Cache invalidates when these files change
- outputs: Directories to cache after successful build
If your build hasn’t changed, Turborepo will restore from cache instantly, saving significant time.
Testing the Build Locally
Before deploying, test your production build locally:Build Performance Tips
Faster Builds
- Use Turborepo’s caching:
yarn build - Keep dependencies up to date
- Leverage remote caching in CI/CD
Debugging Build Issues
Environment Variables
Vite exposes environment variables prefixed withVITE_:
Environment variables are embedded at build time. Rebuild after changing environment variables.
Next Steps
Once your build is successful:- Learn about deployment options
- Set up CI/CD pipelines
- Configure environment variables for production