Skip to content

Vite is a fast build tool and dev server for modern web apps. In a Vite monorepo, Nx runs and caches Vite tasks across every project so you only rebuild what changed.

The @nx/vite plugin adds inferred tasks and project configuration generators.

You can use Vite with Nx without the plugin and still get task caching, task orchestration, and the project graph.

The @nx/vite plugin supports the following package versions.

PackageSupported Versions
vite^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0

For supported vitest versions, see the @nx/vitest plugin requirements.

Nx generators install the latest supported versions automatically when scaffolding new projects.

Install the plugin:

Terminal window
nx add @nx/vite

Configure an existing project to use Vite:

Terminal window
nx g @nx/vite:configuration --project=my-app

Verify inferred tasks in the project details view:

Terminal window
nx show project my-app --web

Replace my-app with your project name.

Use a framework preset and keep the setup minimal:

Terminal window
npx create-nx-workspace@latest --preset=react-standalone --bundler=vite

For the full framework workflows, see the React introduction or Web app reference.

  • nx dev my-app starts the Vite dev server for the project (same as the deprecated serve target).
  • nx build my-app creates a production build in dist/ (controlled by build.outDir in vite.config.*) and registers the outputs for Nx caching.
  • nx preview my-app serves the production build using Vite preview (runs after build).
  • nx serve-static my-app serves the built assets from dist/ for quick smoke tests.
  • nx typecheck my-app runs TypeScript typechecking when a tsconfig*.json exists in the project.

Replace my-app with your project name.

The @nx/vite plugin infers tasks by reading Vite config files. Any of the following config files will be picked up:

  • vite.config.js
  • vite.config.ts
  • vite.config.mjs
  • vite.config.mts
  • vite.config.cjs
  • vite.config.cts

The configuration directory must also contain a package.json or project.json.

Build tasks are only created when the project is buildable. A project is treated as buildable when any of the following are true:

  • build.lib is set in vite.config.*
  • build.rollupOptions.input or build.rolldownOptions.input is set (Vite 8 uses rolldownOptions)
  • builder.buildApp is set
  • an index.html file exists at the project root

Dev, preview, and serve-static tasks are created for buildable projects. If you are in library mode (build.lib), these tasks are skipped unless you explicitly configure a dev server (e.g. server.host or server.port).

Typecheck tasks are created when a tsconfig*.json file exists in the project.

Configure @nx/vite/plugin in the plugins array in nx.json:

nx.json
{
"plugins": [
{
"plugin": "@nx/vite/plugin",
"options": {
"buildTargetName": "build",
"previewTargetName": "preview",
"serveTargetName": "serve",
"devTargetName": "dev",
"serveStaticTargetName": "serve-static",
"typecheckTargetName": "typecheck",
"compiler": "tsc",
"buildDepsTargetName": "build-deps",
"watchDepsTargetName": "watch-deps"
}
}
]
}

serveTargetName is deprecated; use devTargetName instead. buildDepsTargetName and watchDepsTargetName create tasks that build or watch project dependencies.

OptionDescriptionDefault
buildTargetNameName of the Vite build taskbuild
previewTargetNameName of the Vite preview taskpreview
serveTargetNameName of the deprecated Vite serve taskserve
devTargetNameName of the Vite dev server taskdev
serveStaticTargetNameName of the static file server taskserve-static
typecheckTargetNameName of the typecheck tasktypecheck
compilerTypecheck compiler: tsc, tsgo, or vue-tscauto-detected
buildDepsTargetNameName of the build-deps task for dependency buildsnone
watchDepsTargetNameName of the watch-deps task for dependency watchesnone

The build and typecheck tasks are cached, with build outputs based on your Vite configuration. The dev, preview, and static-server tasks are continuous. When compiler is omitted, Nx uses vue-tsc when it detects a Vite Vue plugin and tsc otherwise.

To stop inference for a specific project, exclude its config file with include/exclude filters in nx.json:

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.

To see what tasks Nx inferred for a project, open the project details view in Nx Console or run:

Terminal window
nx show project my-app --web

A target defaults plugin filter for these tasks must use the exact identifier @nx/vite/plugin.

In CI, Nx runs nx affected to rebuild and retest only the projects a change touches, and caches results to skip repeated work.

For a complete pipeline, see Set up CI.