Skip to main content

Vite Configuration

For basic usage, vinext auto-detects your app/ or pages/ directory and generates a Vite config automatically. No vite.config.ts required. For advanced usage (custom plugins, Cloudflare Workers deployment, build options), create a vite.config.ts file.

Basic Configuration

Pages Router

App Router (Development)

For local development with App Router:

App Router (Cloudflare Workers)

For Cloudflare Workers deployment:

vinext Plugin Options

The vinext() plugin accepts no configuration options. It reads your next.config.js automatically.

Common Customizations

Path Aliases

vinext respects your tsconfig.json path aliases. For manual configuration:

MDX Support

vinext auto-detects @next/mdx in your next.config.js and injects @mdx-js/rollup automatically. For manual configuration:

Environment Variables

Environment variables with the NEXT_PUBLIC_ prefix are exposed to the client automatically:
Access in your code:

Build Options

CSS Processing

PostCSS Configuration

vinext loads postcss.config.js automatically. When using ESM ("type": "module"), rename CJS config files to .cjs:

Virtual Modules

vinext provides virtual entry points for the RSC plugin:
  • virtual:vinext-rsc-entry - RSC environment entry (react-server)
  • virtual:vinext-app-ssr-entry - SSR environment entry (node/workers)
  • virtual:vinext-app-browser-entry - Client environment entry (browser)
  • virtual:vinext-server-entry - Pages Router server entry
These are generated automatically and should not be imported directly in your code.

Multi-Environment Builds

App Router uses @vitejs/plugin-rsc for multi-environment builds:
  1. RSC environment (rsc) - React Server Components rendering
  2. SSR environment (ssr) - HTML generation
  3. Client environment (client) - Browser hydration
The RSC plugin orchestrates these builds automatically. Use vinext build (not vite build directly).

Production Build

Always use the vinext CLI for production builds:
Do not use vite build or vite build --ssr directly. The vinext CLI calls createBuilder() which runs the 5-step multi-environment build pipeline.

Common Patterns

Tailwind CSS

Bundle Analysis

Custom Server Middleware

Use Vite’s configureServer hook:

Migrating from Next.js

If you have next.config.js options that need Vite equivalents: