Overview
This portfolio uses Vite as its build tool, which provides fast builds and optimized production bundles. The build process compiles your React application, optimizes assets, and generates static files ready for deployment.Build Command
The production build is configured inpackage.json:
package.json
Run the build command
Execute the build script to create production-ready files:This command will:
- Compile React components and JavaScript
- Process and optimize CSS (Tailwind CSS)
- Bundle and minify all assets
- Generate optimized image formats
- Create source maps for debugging
Verify build output
After a successful build, you’ll find the production files in the
dist/ directory:Build Configuration
The build is configured invite.config.js:
vite.config.js
Key Features
- React Plugin: Enables Fast Refresh and JSX transformation
- Path Aliases:
@resolves to./srcfor cleaner imports - Automatic Optimization: Vite handles code splitting and tree shaking
Build Optimization
Vite automatically applies several optimizations:Code Splitting
Automatically splits code by routes and dynamic imports for faster initial load
Tree Shaking
Removes unused code from the final bundle
Minification
Minifies JavaScript and CSS using esbuild
Asset Optimization
Optimizes images and inlines small assets as base64
Advanced Build Options
Custom Output Directory
Change the output directory by updatingvite.config.js:
vite.config.js
Base URL for Subdirectory Deployment
If deploying to a subdirectory (e.g.,https://example.com/portfolio/):
vite.config.js
Source Maps
Control source map generation:vite.config.js
Source maps help with debugging in production but increase build size. Consider using
'hidden' for production deployments.Build Performance
Expected Build Times
- Initial Build: 10-30 seconds (depending on project size)
- Subsequent Builds: 5-15 seconds (with Vite’s caching)
Optimization Tips
Reduce Bundle Size
Reduce Bundle Size
- Lazy load routes and components using React.lazy()
- Remove unused dependencies
- Use dynamic imports for heavy libraries
- Optimize images before importing
Speed Up Build Times
Speed Up Build Times
- Use Vite’s dependency pre-bundling
- Minimize the number of plugins
- Leverage Vite’s caching mechanisms
- Consider disabling source maps for faster builds
Common Build Issues
Issue: Build Fails with Memory Error
Solution: Increase Node.js memory limit:Issue: Assets Not Loading
Problem: Assets show 404 errors after deployment Solution: Check yourbase configuration in vite.config.js matches your deployment path.
Issue: Environment Variables Not Working
Problem: Environment variables areundefined in production
Solution: Ensure variables are prefixed with VITE_ and properly set in your hosting platform. See the Hosting Guide for environment variable configuration.
Build Checklist
Before deploying to production:- Run
npm run buildsuccessfully - Test with
npm run preview - Verify all environment variables are set
- Check that all routes work correctly
- Test contact form functionality
- Verify responsive design on multiple devices
- Check browser console for errors
- Test loading performance (use Lighthouse)
Next Steps
Deploy Your Portfolio
Learn how to deploy your built portfolio to popular hosting platforms
