Skip to main content

Configuration Guide

vinext automatically loads your Next.js configuration and translates it to Vite. This guide covers both Next.js config options and Vite customization.

Next.js Configuration

vinext loads and respects your existing next.config.js:
vinext auto-detects configuration file formats:
  • next.config.js (CommonJS)
  • next.config.mjs (ES modules)
  • next.config.ts (TypeScript)
  • next.config.cjs (CommonJS with .cjs extension)

Supported Config Options

basePath

Add a path prefix to your application:
All routes, links, and assets are automatically prefixed:
  • //docs/
  • /about/docs/about
  • <Link href="/blog">/docs/blog

trailingSlash

Control URL trailing slashes:
vinext automatically redirects to the canonical form (308 Permanent Redirect).

env

Add custom environment variables:
Access via process.env.CUSTOM_KEY in both server and client code.
NEXT_PUBLIC_* variables are always available on the client. Other variables are server-only unless explicitly added to env.

output

Control build output format:
Options:
  • 'export' - Full static export (no server required)
  • 'standalone' - Self-contained server (Node.js deployment)
  • undefined - Default (SSR + static optimization)
See Static Export Guide for details.

images

Configure image optimization:
vinext performs runtime image optimization, not build-time. The config controls allowed origins but doesn’t affect build output.

redirects

URL redirects with pattern matching:
Features:
  • Path parameters (:param)
  • Wildcards (:path* for catch-all)
  • Conditional redirects with has/missing

rewrites

Rewrite URLs without changing the browser address:
Three phases:

headers

Add custom HTTP headers:

i18n

Internationalization routing (Pages Router only):
vinext automatically:
  • Prefixes URLs with locale (/fr/about, /de/contact)
  • Detects locale from Accept-Language header
  • Stores preference in NEXT_LOCALE cookie
App Router uses a different i18n approach. See Next.js i18n docs for App Router patterns.

cacheComponents

Enable the “use cache” directive (Next.js 16+):
Allows function and page-level caching:

Function-Form Config

Configs can be functions (useful for per-environment settings):
Available phases:
  • phase-development-server - vinext dev
  • phase-production-build - vinext build
  • phase-production-server - vinext start

Vite Configuration

For advanced customization, create a vite.config.ts:

Auto-Generated Config

Running vinext init or vinext deploy auto-generates a minimal vite.config.ts. App Router:
Pages Router:

TypeScript Path Aliases

vinext automatically resolves TypeScript path aliases from tsconfig.json:
No Vite configuration needed—imports work automatically:
This is handled by vite-tsconfig-paths, which vinext injects automatically.

MDX Support

vinext auto-detects MDX usage and configures @mdx-js/rollup with plugins from your Next.js config:
vinext extracts the remark/rehype plugins and applies them to @mdx-js/rollup automatically. For manual MDX configuration:

CSS and Styling

vinext supports all Vite CSS features out of the box:

Tailwind CSS

Import in your root layout:

CSS Modules

PostCSS

Create postcss.config.cjs (note the .cjs extension for ESM projects):

Build Options

Dev Server Options

Optimization

Aliasing Modules

For native modules that can’t run in Workers:
vinext automatically stubs common native modules (sharp, resvg, satori, lightningcss, @napi-rs/canvas) during vinext deploy.

Environment-Specific Config

Environment Variables

Development (.env.local)

Production (.env.production)

Loading Priority

  1. .env.local (highest priority, not committed)
  2. .env.production or .env.development (environment-specific)
  3. .env (shared defaults)

Runtime Access

vinext Plugin Options

The vinext plugin accepts configuration:
Currently, vinext auto-configures based on your Next.js setup and doesn’t require explicit options. Future versions may add customization points.

Migration from Next.js Config

Webpack Config

Next.js:
vinext: Use Vite plugins instead:

Experimental Options

Most Next.js experimental options are not needed in vinext: Next.js:
vinext: App Router and Server Actions work by default—no configuration needed.

Troubleshooting

Config Not Loading

Problem: Changes to next.config.js aren’t reflected Solution: Restart the dev server. Config is loaded once at startup.

Path Alias Not Working

Problem: Import using @/... fails Solution: Ensure tsconfig.json has correct paths config and baseUrl is set.

PostCSS Error

Error: Error: Cannot find module 'postcss.config.js' Solution: Rename to postcss.config.cjs if your project has "type": "module" in package.json.

Environment Variable Not Available

Problem: process.env.MY_VAR is undefined in client code Solution: Client-side variables must start with NEXT_PUBLIC_:

Next Steps

Deployment

Deploy your configured application

Cloudflare Workers

Deploy to Cloudflare with advanced config

Static Export

Configure static site generation

Vite Documentation

Complete Vite configuration reference