Build Process
Configure environment variables
Create a
.env.local file (or configure in your hosting platform) with required environment variables:.env.local
Run the production build
Build the application for production:This command:
- Compiles Next.js configuration (
next.config.ts→next.config.mjs) - Generates all static pages using
getStaticPropsandgetStaticPaths - Optimizes images and assets
- Creates production bundles with code splitting
Build Configuration
Next.js Configuration
The build is configured innext.config.ts:
next.config.ts
next.config.ts:19.
Environment Variable Validation
Environment variables are validated on startup insrc/utils/config.ts:
src/utils/config.ts
Static Site Generation (SSG)
How SSG Works
The project uses Next.js Static Site Generation to pre-render all pages at build time:- Build Time:
getStaticPathsgenerates a list of all pages - Build Time:
getStaticPropsfetches data for each page - Runtime: Pages are served as static HTML
- Revalidation: ISR updates pages in the background
Incremental Static Regeneration (ISR)
Pages are automatically revalidated after a set time:src/pages/anime/[animeSlug]/index.tsx
- First request after 1 hour gets stale data (fast)
- Triggers regeneration in background
- Subsequent requests get fresh data
Build Time Caching
The project caches data between pages during build:src/pages/anime/[animeSlug]/index.tsx
src/pages/anime/[animeSlug]/index.tsx:189.
Deployment Options
Vercel (Recommended)
- Connect your GitHub repository to Vercel
- Configure environment variables in the Vercel dashboard
- Deploy automatically on push
vercel.json
Docker
Create a Dockerfile for containerized deployment:Dockerfile
Static Export (Not Supported)
Note: This project cannot be deployed as a fully static export because it uses:- ISR (Incremental Static Regeneration)
- Server-side API routes (
/api/*) notFound: trueingetStaticProps
Performance Optimization
Bundle Analysis
Analyze your bundle size:- Size of each package
- Code splitting effectiveness
- Opportunities for optimization
Build Optimization
The project includes several optimizations:- Code Splitting: Automatic per-route splitting
- Image Optimization: Next.js Image component
- Styled Components: SSR with
styledComponents: true - Tree Shaking: Removes unused code
- Minification: Production builds are minified
Static Generation Timeout
For large sites, increase the timeout:next.config.ts
Security Headers
The project includes security headers innext.config.ts:33:
next.config.ts
Troubleshooting
Build Fails
- Check environment variables: Ensure all required variables are set
- Check TypeScript errors: Run
npm run type-check - Check linting: Run
npm run lint - Clear cache: Delete
.nextfolder and rebuild
Out of Memory
Increase Node.js memory:Slow Build
For faster development builds, use minimal build mode:Monitoring
Track API requests during build:src/pages/index.tsx
Best Practices
- Set appropriate
revalidatetimes for ISR (1 hour is a good default) - Use build-time caching to reduce API calls
- Monitor bundle size with
ANALYZE=true - Test production build locally before deploying
- Use environment-specific variables for different stages
- Set up error tracking (Sentry, etc.)
- Configure CDN for static assets
- Enable compression on your server
- Use a reverse proxy (Nginx) for additional security
- Monitor API rate limits during build
Next Steps
- Learn about adding pages
- Understand creating components
- Read about working with the API