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
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

Options

buildTarget

Required
string

Target which builds the application.

proxyConfig

string

Path to the proxy configuration file.

staticFilePath

string

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