project.json:

1//... 2"my-app": { 3 "targets": { 4 //... 5 "serve": { 6 "executor": "@nx/vite:dev-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 serve 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 serve target options:

1//... 2"my-app": { 3 "targets": { 4 //... 5 "serve": { 6 "executor": "@nx/vite:dev-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. Only used to retrieve the configuration as the dev-server does not build the code.

port

number

Port to listen on.

buildLibsFromSource

boolean
Default: true

Read buildable libraries from source instead of building them separately.

cors

boolean

Configure CORS for the dev server.

clearScreen

boolean

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

force

boolean

Force the optimizer to ignore the cache and re-bundle

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

hmr

boolean

Enable hot module replacement. For more options, use the 'hmr' option in the Vite configuration file.

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.