Build Process
The Pengrafic template uses Next.js 14 with the App Router. The build process compiles your application into an optimized production bundle.Build Command
next build which:
- Compiles TypeScript to JavaScript
- Optimizes and minifies code
- Generates static pages where possible
- Creates server-side rendered pages
- Optimizes images and assets
Production Server
After building, start the production server:next start on port 3000 by default.
Environment Variables
Before deploying, ensure you have the following environment variables configured:Always use environment variables for sensitive data. Never commit
.env.local files to version control.Required Variables
Environment Variable Naming
NEXT_PUBLIC_*variables are exposed to the browser- Variables without
NEXT_PUBLIC_prefix are server-side only - Use different values for development and production environments
Pre-Deployment Checklist
Test Build Locally
Run Visit
npm run build locally to ensure there are no build errors:http://localhost:3000 to verify the production build works correctly.Configure Environment Variables
Prepare all required environment variables for your production environment. Update any URLs, API keys, or configuration values that differ from development.
Review Security Settings
- Enable
reactStrictMode(already enabled) - Consider setting
poweredByHeader: falseto hide Next.js version - Review CORS and CSP policies if needed
Deployment Options
Pengrafic can be deployed to various platforms. Choose the option that best fits your needs:Vercel (Recommended)
Vercel is the creator of Next.js and offers seamless deployment with zero configuration.- Automatic builds on git push
- Edge network with global CDN
- Preview deployments for pull requests
- Built-in analytics and monitoring
Netlify
Netlify provides excellent Next.js support with serverless functions and edge capabilities.- Git-based deployment workflow
- Built-in CI/CD pipeline
- Form handling and serverless functions
- Split testing and branch deploys
Self-Hosted
Deploy to your own infrastructure using:- Docker containers
- VPS (DigitalOcean, Linode, etc.)
- AWS, Google Cloud, or Azure
- Kubernetes clusters
Self-hosting requires managing your own infrastructure, SSL certificates, and scaling. Use a platform like Vercel or Netlify for easier deployment.
Build Output
Thenext build command generates:
.next/directory with compiled application- Static assets in
.next/static/ - Server-side code for dynamic pages
- Optimized images and fonts
Output Structure
Performance Optimization
The template includes several optimizations:- SWC Minification: Faster minification with
swcMinify: true - Image Optimization: Modern formats (AVIF, WebP) with
next/image - Code Splitting: Automatic code splitting per route
- Font Optimization: Automatic font optimization
- Caching: Minimum cache TTL of 60 seconds for images
Monitoring and Analytics
After deployment, consider adding:- Vercel Analytics: Built-in performance monitoring
- Google Analytics: User behavior tracking
- Sentry: Error tracking and reporting
- Uptime Monitoring: Service availability checks
Troubleshooting
Build Fails
- Check TypeScript errors:
npm run lint - Clear cache:
rm -rf .nextand rebuild - Verify all dependencies are installed:
npm install
Runtime Errors
- Check environment variables are set correctly
- Review server logs in your deployment platform
- Ensure API endpoints are accessible from production
Image Loading Issues
- Verify image domains in
next.config.js - Check image paths are correct
- Ensure external image sources allow CORS