project.json:

1//... 2"my-app": { 3 "targets": { 4 //... 5 "preview": { 6 "executor": "@nx/vite:preview-server", 7 "defaultConfiguration": "development", 8 "options": { 9 "buildTarget": "my-app:build", 10 }, 11 "configurations": { 12 ... 13 } 14 }, 15 } 16} 17
Nx 15 and lower use @nrwl/ instead of @nx/
1nx preview my-app 2

Examples

You can always set the port in your vite.config.ts file. However, you can also set it directly in your project.json file, in the preview target options:

1//... 2"my-app": { 3 "targets": { 4 //... 5 "preview": { 6 "executor": "@nx/vite:preview-server", 7 "defaultConfiguration": "development", 8 "options": { 9 "buildTarget": "my-app:build", 10 "port": 4200, 11 }, 12 "configurations": { 13 ... 14 } 15 }, 16 } 17} 18
Nx 15 and lower use @nrwl/ instead of @nx/

Options

buildTarget

Required
string

Target which builds the application.

clearScreen

boolean

Set to false to prevent Vite from clearing the terminal screen when logging certain messages.

host

oneOf [boolean, string]

Specify which IP addresses the server should listen on.

https

oneOf [boolean, object: object]

Serve using HTTPS. https://vitejs.dev/config/server-options.html#server-https

logLevel

string
Accepted values: info, warn, error, silent

Adjust console output verbosity.

mode

string

Mode to run the server in.

open

oneOf [boolean, string]

Automatically open the app in the browser on server start. When the value is a string, it will be used as the URL's pathname.

proxyConfig

string

Path to the proxy configuration file.

port

number

Port to listen on.

staticFilePath

string

Path where the build artifacts are located. If not provided then it will be infered from the buildTarget executor options as outputPath