recipes/nextjs
import '@catapultjs/deploy/recipes/nextjs'This recipe runs the Next.js build on the server. It does not override deploy:update_code, so combine it with a transfer recipe such as git or rsync.
It is designed for Next.js standalone output. After next build, it symlinks public and .next/static into .next/standalone/ when that directory exists.
See the example Next.js project for a complete setup, or go directly to deploy.ts.
Tasks
| Task | Inserted | Description |
|---|---|---|
deploy:build | after deploy:shared | Overrides the built-in build task, runs next build, and prepares standalone |
The recipe runs the build command from /.
Configuration
| Key | Type | Default | Description |
|---|---|---|---|
shared_files | string[] | ['.env'] | Files symlinked from shared/ into each release |
nextjs_path | string | '' | Sub-path to the Next.js app within the repository |
nextjs_out_path | string | '.next/standalone/' | Standalone output path receiving the symlinks |
source_path | string | '' | Used as the default value for nextjs_path |
import { set } from '@catapultjs/deploy'
set('nextjs_path', 'apps/web')
import '@catapultjs/deploy/recipes/nextjs'For standalone output, make sure your Next.js config enables it:
const nextConfig = {
output: 'standalone',
}
export default nextConfigNext.js creates .next/standalone/server.js for standalone deployments. It does not copy public or .next/static into the standalone directory by default; this recipe links them into the standalone output after the build so the generated server can serve them.
For PM2, use the standalone server entry from the active release:
const path = require('path')
const deployPath = '/home/deploy/myapp'
module.exports = {
apps: [
{
name: 'next',
cwd: path.join(deployPath, 'current'),
script: '.next/standalone/server.js',
},
],
}See Next.js' output: 'standalone' documentation for the upstream standalone output details.