Builds your Next.js application for production. Automatically detects whether you’re using App Router or Pages Router and runs the appropriate build pipeline.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/cloudflare/vinext/llms.txt
Use this file to discover all available pages before exploring further.
Usage
Options
Show help for this command. Can also use
-h.Behavior
Router Detection
vinext automatically detects your router type and runs the appropriate build:App Router Build Process
For App Router projects, vinext usescreateBuilder() to run a multi-environment build:
-
RSC Environment (
dist/server/index.js)- React Server Components runtime
- Server-side route handlers
- Server Actions
-
SSR Environment (
dist/server/ssr/index.js)- Server-side rendering for Client Components
- Imported by RSC entry at runtime
-
Client Environment (
dist/client/)- Hydration scripts
- Client Component bundles
- Static assets (CSS, images, fonts)
Pages Router Build Process
For Pages Router projects, vinext runs two builds:-
Client Build (
dist/client/)- Bundled JavaScript (code-split by route)
- CSS files (extracted and minified)
- Static assets
.vite/manifest.jsonand.vite/ssr-manifest.json
-
Server Build (
dist/server/entry.js)- SSR entry point
- API route handlers
- Server-side rendering logic
Build Output
Directory Structure
Build Artifacts
Client Assets
Client Assets
- JavaScript bundles: Code-split by route and lazy-loaded
- CSS files: Extracted, minified, and automatically injected
- Images/fonts: Copied to
dist/client/with hashed filenames - Manifest files: Used by SSR to map modules to assets
Server Entry
Server Entry
- RSC handler (App Router): Renders React Server Components to RSC stream
- SSR handler (Pages Router): Renders pages to HTML on request
- API routes: Bundled into server entry
- Server Actions (App Router): Bundled with RSC entry
Manifests
Manifests
- manifest.json: Maps module IDs to built asset paths
- ssr-manifest.json: Maps Client Component imports to asset URLs for preloading
Build Optimizations
vinext applies these optimizations automatically:Code Splitting
Each page/route gets its own bundle:Tree Shaking
Unused code is eliminated at build time:Minification
All JavaScript and CSS is minified:- JavaScript: Minified with esbuild (fast and effective)
- CSS: Minified with cssnano
- HTML: Inline scripts/styles are minified
Asset Hashing
All assets get content-based hashes for optimal caching:Configuration
Custom Build Config
Customize the build invite.config.ts:
Environment Variables
Build-time environment variables:Examples
Basic Build
Build your app:Build and Start
Build and immediately start the production server:Build for Cloudflare Workers
Build with Cloudflare-specific config:CI/CD Build
Typical CI build script:Build Performance
vinext builds are faster than Next.js:| Project Size | Next.js | vinext | Improvement |
|---|---|---|---|
| Small (less than 20 pages) | ~15s | ~8s | 1.9x faster |
| Medium (20-100 pages) | ~45s | ~18s | 2.5x faster |
| Large (100+ pages) | ~120s | ~35s | 3.4x faster |
Benchmarks from real-world projects. Your results may vary based on complexity and dependencies.
Troubleshooting
Build Fails with “Module not found”
Ensure all dependencies are installed:@vitejs/plugin-rsc is installed:
Out of Memory Error
Increase Node.js memory limit:Large Bundle Size
Analyze your bundle:stats.html to see what’s in your bundle.
Next Steps
start Command
Start the production server
deploy Command
Deploy to Cloudflare Workers