project.json:

//... { "name": "acme", "$schema": "node_modules/nx/schemas/project-schema.json", "sourceRoot": ".", "projectType": "application", "targets": { //... "serve": { "executor": "@nx/next:server", "defaultConfiguration": "production", "options": { "buildTarget": "acme:build", "dev": true } } //... } }
Nx 15 and lower use @nrwl/ instead of @nx/
nx run acme:serve

Examples

For Next.js Standalone projects

This is the default configuration for Next.js standalone projects. Our @nx/next:server executor is integrated to use Next.js' CLI. You can read more about the serve options at Next.js CLI Options

"serve": { "executor": "@nx/next:server", "defaultConfiguration": "development", "options": { "buildTarget": "acme:build", "dev": true }, "configurations": { "development": { "buildTarget": "acme:build:development", "dev": true }, "production": { "buildTarget": "acme:build:production", "dev": false } } },
Nx 15 and lower use @nrwl/ instead of @nx/

Options

buildTarget

Required
string

Target which builds the application.

port

number
Default: 4200

Port to listen on.

buildLibsFromSource

boolean
Default: true

Read buildable libraries from source instead of building them separately.

customServerTarget

string

Target which builds the custom server.

dev

boolean
Default: true

Serve the application in the dev mode.

hostname

string

Hostname on which the application is served.

keepAliveTimeout

number

Max milliseconds to wait before closing inactive connection.

quiet

boolean
Default: false

Hide error messages containing server information.

staticMarkup

boolean
Default: false

Static markup.

turbo

boolean

Activate the incremental bundler for Next.js, which is implemented in Rust. Please note, this feature is exclusively available in development mode.