Vite is a fast build tool and dev server for modern web apps.
The @nx/vite plugin adds inferred targets and project configuration generators.
You can use Vite with Nx without the plugin and still get task caching, task orchestration, and the project graph.
Add to an existing workspace
Section titled “Add to an existing workspace”Install the plugin:
nx add @nx/viteConfigure an existing project to use Vite:
nx g @nx/vite:configuration --project=my-appVerify inferred tasks in the project details view:
nx show project my-app --webReplace my-app with your project name.
Create a new workspace
Section titled “Create a new workspace”Use a framework preset and keep the setup minimal:
npx create-nx-workspace@latest --preset=react-standalone --bundler=vitenpx create-nx-workspace@latest --preset=web-components --bundler=viteFor the full framework workflows, see the React introduction or Web app reference.
Local Development
Section titled “Local Development”nx dev my-appstarts the Vite dev server for the project (same as the deprecatedservetarget).nx build my-appcreates a production build indist/(controlled bybuild.outDirinvite.config.*) and registers the outputs for Nx caching.nx preview my-appserves the production build using Vite preview (runs afterbuild).nx serve-static my-appserves the built assets fromdist/for quick smoke tests.nx typecheck my-appruns TypeScript typechecking when atsconfig*.jsonexists in the project.
Replace my-app with your project name.
Configuration
Section titled “Configuration”Configure Task Inference
Section titled “Configure Task Inference”The @nx/vite plugin infers tasks by reading Vite config files. Any of the following config files will be picked up:
vite.config.jsvite.config.tsvite.config.mjsvite.config.mtsvite.config.cjsvite.config.cts
Build targets are only created when the project is buildable. A project is treated as buildable when any of the following are true:
build.libis set invite.config.*build.rollupOptions.inputis setbuilder.buildAppis set- an
index.htmlfile exists at the project root
Dev, preview, and serve-static targets are created for buildable projects. If you are in library mode (build.lib), these targets are skipped unless you explicitly configure a dev server (e.g. server.host or server.port).
Typecheck targets are created when a tsconfig*.json file exists in the project.
Plugin Options
Section titled “Plugin Options”Configure @nx/vite/plugin in the plugins array in nx.json:
{ "plugins": [ { "plugin": "@nx/vite/plugin", "options": { "buildTargetName": "build", "previewTargetName": "preview", "serveTargetName": "serve", "devTargetName": "dev", "serveStaticTargetName": "serve-static", "typecheckTargetName": "typecheck", "buildDepsTargetName": "build-deps", "watchDepsTargetName": "watch-deps" } } ]}serveTargetName is deprecated; use devTargetName instead. buildDepsTargetName and watchDepsTargetName create targets that build or watch project dependencies.
| Option | Description | Default |
|---|---|---|
buildTargetName | Name of the Vite build target | build |
previewTargetName | Name of the Vite preview target | preview |
serveTargetName | Name of the deprecated Vite serve target | serve |
devTargetName | Name of the Vite dev server target | dev |
serveStaticTargetName | Name of the static file server target | serve-static |
typecheckTargetName | Name of the typecheck target | typecheck |
buildDepsTargetName | Name of the build-deps target for dependency builds | none |
watchDepsTargetName | Name of the watch-deps target for dependency watches | none |
Disable or Scope Inference
Section titled “Disable or Scope Inference”To stop inference for a specific project, exclude its config file with include/exclude filters in nx.json:
{ "plugins": [ { "plugin": "@nx/vite/plugin", "exclude": ["apps/legacy/**"] } ]}To avoid specific targets, adjust the config files that trigger them. For example, remove tsconfig*.json to stop typecheck, or use library mode (build.lib) to skip dev, preview, and serve-static unless you set dev server options.
View Inferred Tasks
Section titled “View Inferred Tasks”To see what tasks Nx inferred for a project, open the project details view in Nx Console or run:
nx show project my-app --webCI and Scale
Section titled “CI and Scale”Use Nx to keep CI fast in large monorepos:
- Run only affected Vite projects:
nx affected -t build,typecheck. - Enable remote caching with Nx Cloud using
nx connect. - Follow the CI setup guide for a full pipeline.