Skip to main content
Builds your Next.js application for production. Automatically detects whether you’re using App Router or Pages Router and runs the appropriate build pipeline.

Usage

Options

flag
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 uses createBuilder() to run a multi-environment build:
This creates three separate builds:
  1. RSC Environment (dist/server/index.js)
    • React Server Components runtime
    • Server-side route handlers
    • Server Actions
  2. SSR Environment (dist/server/ssr/index.js)
    • Server-side rendering for Client Components
    • Imported by RSC entry at runtime
  3. 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:
This creates:
  1. Client Build (dist/client/)
    • Bundled JavaScript (code-split by route)
    • CSS files (extracted and minified)
    • Static assets
    • .vite/manifest.json and .vite/ssr-manifest.json
  2. Server Build (dist/server/entry.js)
    • SSR entry point
    • API route handlers
    • Server-side rendering logic

Build Output

Directory Structure

Build Artifacts

  • 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
  • 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
  • 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:
Shared code is extracted into separate chunks:

Tree Shaking

Unused code is eliminated at build time:
Only code that’s actually imported and used is included in the bundle.

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:
You can set far-future cache headers (1 year) because hashes change when content changes.

Configuration

Custom Build Config

Customize the build in vite.config.ts:

Environment Variables

Build-time environment variables:
These are embedded into the client bundle at build time.

Examples

Basic Build

Build your app:
Output:

Build and Start

Build and immediately start the production server:

Build for Cloudflare Workers

Build with Cloudflare-specific config:
Then build:
Or use the one-command deploy:

CI/CD Build

Typical CI build script:

Build Performance

vinext builds are faster than Next.js:
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:
For App Router, ensure @vitejs/plugin-rsc is installed:

Out of Memory Error

Increase Node.js memory limit:
Or add to package.json:

Large Bundle Size

Analyze your bundle:
After build, open stats.html to see what’s in your bundle.

Next Steps

start Command

Start the production server

deploy Command

Deploy to Cloudflare Workers