Builds a Next.js project with @vercel/next without invoking vercel build, so
it does not perform Vercel CLI project lookup, auth, or environment pull checks.
Once published or otherwise available to npm, run it with npx:
npx next-bundle /path/to/next-projectFrom this package checkout, pass the project path explicitly:
npm install
npm run build -- /path/to/next-projectFrom any directory, pass the project path after --. Relative paths are
resolved from the directory where you invoked npm, not from this package:
npm --prefix packages/next-bundle install
npm --prefix packages/next-bundle run build -- .
npm --prefix packages/next-bundle run build -- ../another-project
npm --prefix packages/next-bundle run build -- /absolute/path/to/projectYou can also use --project-root instead of the positional path:
npx next-bundle --project-root /absolute/path/to/project
npm --prefix packages/next-bundle run build -- --project-root /absolute/path/to/projectIf the project path is omitted, the command builds the directory where npm was invoked.
The output is written to:
.next-bundleThe build also writes a local Node.js server:
node .next-bundle/server.mjsIt also writes an optimized shared dependency tree next to the server:
.next-bundle/node_modulesThat folder is materialized from .next/next-server.js.nft.json, plus any
extra dependency files referenced by Vercel's generated function file maps and
the local runtime packages needed by next-bundle. The function directories
reuse this shared node_modules through Node's normal module resolution instead
of carrying duplicated dependency copies.
Set PORT to choose a port:
PORT=4000 node .next-bundle/server.mjsBy default the package:
- skips dependency installation in the target project
- runs
npm run build - uses the target project's declared
nextversion - calls
@vercel/nextdirectly and writes Build Output API files with Vercel's own output writer - writes a local Node.js server that serves the generated Build Output API files
- handles
/_next/imagelocally, including Photon-backed raster resizing when WebAssembly is available
To package an existing .next directory without rebuilding:
npx next-bundle . --skip-build
npm --prefix packages/next-bundle run build -- . --skip-build