Files
nrwl--nx/packages/vite/docs/preview-server-examples.md
T
2026-07-13 12:38:36 +08:00

1.6 KiB

title, description
title description
Examples for the Vite preview server executor This page contains examples for the Vite @nx/vite:preview-server executor.

project.json:

//...
"my-app": {
    "targets": {
        //...
        "preview": {
            "executor": "@nx/vite:preview-server",
            "defaultConfiguration": "development",
            "options": {
                "buildTarget": "my-app:build",
            },
            "configurations": {
                ...
            }
        },
    }
}
nx preview my-app

Examples

Set up a custom port

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:

//...
"my-app": {
    "targets": {
        //...
        "preview": {
            "executor": "@nx/vite:preview-server",
            "defaultConfiguration": "development",
            "options": {
                "buildTarget": "my-app:build",
                "port": 4200,
            },
            "configurations": {
                ...
            }
        },
    }
}
Specify a proxyConfig

You can specify a proxy config by pointing to the path of your proxy configuration file:

//...
"my-app": {
    "targets": {
        //...
        "preview": {
            "executor": "@nx/vite:preview-server",
            "defaultConfiguration": "development",
            "options": {
                "buildTarget": "my-app:build",
                "proxyConfig": "apps/my-app/proxy.conf.json"
            },
            "configurations": {
                ...
            }
        },
    }
}