Build Command
To create a production build:- Bundles all source files using Vite
- Optimizes assets (minification, tree-shaking)
- Applies Terser minification with console removal
- Implements manual code splitting strategy
- Outputs to the
dist/directory
Vite Configuration
The build process is configured invite.config.ts. Here’s the complete configuration:
vite.config.ts
Build Optimization Strategies
Terser Minification
The build uses Terser for JavaScript minification with aggressive optimization:vite.config.ts
Why Console Removal?
- Reduces bundle size
- Improves runtime performance
- Prevents sensitive information leakage
- Cleaner production console
Manual Code Splitting
The build implements a manual chunks strategy for optimal loading performance:vite.config.ts
Chunk Strategy
| Chunk | Contains | Reason |
|---|---|---|
vendor.js | All node_modules except react-github-calendar | Core dependencies loaded immediately |
vendor-github.js | react-github-calendar library | Lazy loaded with React Suspense to prevent page break |
index.js | Application code | Main bundle |
CSS Code Splitting
CSS is split per route for optimal loading:vite.config.ts
CSS Injection Plugin
The vite-plugin-css-injected-by-js plugin is critical for Tailwind CSS v4:vite.config.ts
Why This Plugin?
- Tailwind CSS v4 requires special handling in Vite
- Injects CSS via JavaScript for proper loading order
- Prevents FOUC (Flash of Unstyled Content)
- Ensures styles are available before first paint
Build Output Structure
After runningnpm run build, the dist/ directory structure:
Asset Hashing
All assets include content hashes in filenames:index-a7f3d2e1.jsvendor-9b4c8f2a.js
- Long-term caching (1 year+)
- Cache invalidation on content changes
- Parallel downloads from CDN
Preview Production Build
Test the production build locally before deployment:dist/ directory, allowing you to:
- Test production optimizations
- Verify asset loading
- Check bundle sizes
- Test on real devices via network URL
Clean Build
Remove the build output directory:- Build artifacts are corrupted
- You need a fresh build
- Debugging build issues
- Switching between branches
Build Performance
Build Time Optimization
Typical build times:- Initial build: 5-10 seconds
- Incremental builds: 2-5 seconds
Bundle Size Analysis
Analyze bundle sizes after build:index.js: ~50-80 KBvendor.js: ~150-200 KBvendor-github.js: ~30-50 KBindex.css: ~10-20 KB
Performance Metrics
Target Lighthouse scores:- Performance: 90+
- Accessibility: 100
- Best Practices: 100
- SEO: 100
Deployment
The portfolio is optimized for deployment on:- Vercel (recommended)
- Netlify
- Cloudflare Pages
- Any static hosting service
Vercel Deployment
The project includes Vercel Analytics and Speed Insights:Build Command for Hosting
Output Directory
Troubleshooting Builds
Build Fails
If the build fails:Type Errors During Build
Run type checking first:Missing Assets
Ensure all assets are in thepublic/ directory:
- Fonts in
/fonts/ - Images in
/img/ cv.xmlin root
CSS Not Loading
VerifycssInjectedByJsPlugin() is in the Vite plugins array (vite.config.ts:14).
Large Bundle Sizes
If bundles are too large:- Check for unused dependencies
- Verify tree-shaking is working
- Review manual chunks strategy
- Consider lazy loading more components
