Skip to main content

NextAdapter

The NextAdapter interface defines the contract for adapting Next.js builds to the Vercel platform.

Properties

name
string
required
The name of the adapter. For the Vercel adapter, this is set to "Vercel".
onBuildComplete
function
required
Async function called when the Next.js build is complete. Transforms build outputs into Vercel deployment format.

onBuildComplete

The onBuildComplete hook is the core function that transforms Next.js build outputs into the Vercel Build Output API format.

Parameters

The function receives a single configuration object with the following properties:
routing
object
required
Routing configuration from Next.js build including rewrites, redirects, headers, and dynamic routes.
config
NextConfig
required
Next.js configuration object including basePath, i18n, images, and other settings.
buildId
string
required
Unique identifier for the current build.
outputs
object
required
Collection of all build outputs categorized by type.
distDir
string
required
Absolute path to the .next build directory.
repoRoot
string
required
Absolute path to the repository root directory.
projectDir
string
required
Absolute path to the Next.js project directory.
nextVersion
string
required
Version string of Next.js being used (e.g., “14.1.0”).

Return value

Returns a Promise<void> that resolves when all build outputs have been processed and written to the Vercel output directory.

Behavior

The onBuildComplete hook performs the following operations:
  1. Creates the Vercel output directory at {distDir}/output
  2. Processes public files and static outputs
  3. Handles Edge Functions and Node.js functions
  4. Processes middleware if present
  5. Handles prerender outputs for ISR/SSG pages
  6. Generates the routing configuration
  7. Writes the final config.json file
import type { NextAdapter } from 'next';

const myAdapter: NextAdapter = {
  name: 'Vercel',
  async onBuildComplete({
    routing,
    config,
    buildId,
    outputs,
    distDir,
    repoRoot,
    projectDir,
    nextVersion,
  }) {
    // Transform Next.js build outputs to Vercel format
    const vercelOutputDir = path.join(distDir, 'output');
    await fs.mkdir(vercelOutputDir, { recursive: true });
    
    // Process outputs...
  },
};

export = myAdapter;

Notes

  • The adapter handles both Node.js and Edge runtime outputs
  • Middleware is supported for both runtimes
  • Static files are optimized with content-type overrides
  • i18n configuration is transformed into Vercel wildcard routing
  • The adapter preserves ISR and PPR (Partial Prerendering) configurations

Build docs developers (and LLMs) love