TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/nrwl/nx/llms.txt
Use this file to discover all available pages before exploring further.
@nx/vite plugin integrates Vite and Vitest into your Nx workspace. It can infer build, serve, test, and preview targets automatically from vite.config.ts, and provides generators to add Vite configuration to existing projects.
Installation
@nx/vite requires vite (^5, ^6, ^7, or ^8) and vitest (^1.3.1, ^2, ^3, or ^4) as peer dependencies.What the plugin provides
Generators
Add Vite or Vitest configuration to existing projects. Set up TypeScript path aliases for workspace libraries.
Executors
Build with Vite, serve with the Vite dev server, test with Vitest, and preview production builds.
Inferred tasks
Automatically detects
vite.config.ts files and infers build, serve, test, and preview targets without any manual configuration.Generators
configuration
Add Vite configuration to an existing project. This is the primary generator for migrating a project to use Vite.vitest
Add a Vitest configuration to an existing project without adding a full Vite build setup.setup-paths-plugin
Add thenxViteTsPaths plugin to an existing vite.config.ts to enable TypeScript path aliases for workspace libraries.
convert-to-inferred
Migrate existing projects that use@nx/vite:build or @nx/vite:test executors to use the inferred task plugin instead.
Executors
build
Build a project using Vite. Runsvite build under the hood.
dev-server
Start the Vite development server with hot module replacement.test
Run unit tests using Vitest.preview-server
Preview the production build locally using Vite’s preview server.Inferred tasks
When@nx/vite/plugin is registered in nx.json, Nx scans for vite.config.ts (or .js, .mts, .mjs) files and automatically infers targets from them. No project.json target configuration is needed.
Inferred tasks read their configuration directly from
vite.config.ts. Options like outputPath, port, and mode are picked up from the config file rather than project.json.Configuration examples
vite.config.ts for a React app
vite.config.ts with Vitest
TypeScript path aliases
ThenxViteTsPaths plugin reads your tsconfig.base.json path aliases and applies them to the Vite build, enabling imports like @myorg/mylib to resolve correctly without manual alias configuration.
