Learn how the build process works and how to optimize your Astro portfolio for production.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Hazielgmz/astro-Portfolio/llms.txt
Use this file to discover all available pages before exploring further.
Build Overview
The build process transforms your Astro project into production-ready assets optimized for deployment.Build Command
astro build command defined in package.json:
SSR Configuration
Your portfolio is configured for server-side rendering (SSR) inastro.config.mjs:
Why SSR?
- Dynamic Content: Render pages on-demand with real-time data
- API Routes: Create serverless API endpoints
- Personalization: Serve user-specific content
- SEO: Server-rendered HTML for search engines
Vercel Serverless Adapter
The@astrojs/vercel adapter is configured for serverless deployment:
Features
- Serverless Functions: Each page becomes a serverless function
- Edge Network: Distributed globally for low latency
- Automatic Scaling: Handles traffic spikes automatically
- Zero Configuration: Works out of the box with Vercel
Output Directory
The Vercel adapter outputs to.vercel/output/ directory:
The
.vercel directory is automatically generated and should be added to .gitignore.Build Process Steps
When you runastro build, the following happens:
- Type Checking: TypeScript files are validated
- Component Processing: Astro components are compiled
- Style Processing: Tailwind CSS is processed via Vite
- Asset Optimization: Images and static files are optimized
- Bundle Generation: JavaScript and CSS are bundled and minified
- Adapter Output: Vercel adapter creates serverless functions
Build Optimization Tips
1. Optimize Dependencies
Keep yourpackage.json lean:
2. Image Optimization
Use Astro’s built-in image optimization:3. Code Splitting
Astro automatically code-splits by page. For components, use dynamic imports:4. CSS Optimization
Tailwind CSS is configured via Vite plugin and automatically purges unused styles:5. Environment Variables
Use environment variables for configuration:Preview Build Locally
Test your production build locally before deploying:http://localhost:4321 by default.
Troubleshooting Common Issues
Build Fails with Module Errors
Problem: Missing or incompatible dependencies Solution:TypeScript Errors
Problem: Type checking fails during build Solution:Tailwind Styles Missing
Problem: Styles not applied in production Solution:- Ensure
@tailwindcss/viteplugin is configured - Check that classes are used in your components (not dynamically generated)
- Verify Tailwind directives are in your CSS
Large Bundle Size
Problem: Slow page loads due to large JavaScript bundles Solution:- Use
astro:assetsfor image optimization - Minimize client-side JavaScript
- Enable tree-shaking by avoiding side effects
- Consider lazy loading heavy components
Environment Variables Not Working
Problem: Variables undefined in production Solution:- Add variables to Vercel dashboard
- Use correct prefix (
PUBLIC_for client-side) - Redeploy after adding new variables
Build Performance
Typical Build Times
- Small portfolio (5-10 pages): 10-30 seconds
- Medium portfolio (10-20 pages): 30-60 seconds
- Large portfolio (20+ pages): 1-2 minutes
Improving Build Speed
- Reduce dependencies: Only install what you need
- Use build caching: Vercel automatically caches dependencies
- Optimize images: Pre-optimize large images before adding them
- Parallel builds: Vercel uses parallel processing automatically