Configure and integrate Vite in Nx monorepos for applications and libraries. Covers vite.config.ts setup, framework plugins, TypeScript path resolution, asset copying, library mode builds, and Vitest integration. Use when: adding Vite to an Nx project, migrating from Webpack, configuring Vitest, fixing tsconfig path resolution, or setting up library mode. Triggers: "add vite", "nx vite", "vite setup", "vite.config.ts", "vitest config", "library mode", "nxViteTsPaths", "copy assets", "vite path aliases", "migrate webpack to vite" Examples: - user: "Add Vite to this Nx app" -> install plugin and configure vite.config.ts - user: "Vitest is failing in Nx" -> fix test config and cache/coverage paths - user: "Path aliases break in Vite" -> add nxViteTsPaths plugin - user: "Set up Vite for my Nx library" -> configure lib mode + dts + externals
68
85%
Does it follow best practices?
Impact
—
No eval scenarios have been run
Passed
No known issues
Configure Vite as the build tool in Nx workspaces with predictable, cache-friendly defaults.
Nx and Vite each have their own opinions about project structure. The integration works by making Vite defer to Nx for path resolution and task orchestration while Nx defers to Vite for bundling. The critical bridge is nxViteTsPaths() — without it, workspace path aliases silently resolve to nothing and builds fail with cryptic module-not-found errors.
Think in two layers: workspace-level (Nx executor targets, cache dirs, project boundaries) and build-level (Vite plugins, rollup options, output formats). Workspace-level decisions live in project.json; build-level decisions live in vite.config.ts. Keep them separate and each layer becomes predictable.
Library mode differs meaningfully from app mode: apps bundle everything together, libraries externalize peer deps to avoid duplication in consumers. The distinction determines whether rollupOptions.external and vite-plugin-dts are needed.
| Scenario | Use This Skill |
|---|---|
| Adding Vite to an existing Nx app or lib | Yes |
| Migrating from Webpack or CRA to Vite inside Nx | Yes |
| Setting up Vitest alongside an existing Vite config | Yes |
Fixing @org/lib path aliases failing in Vite builds | Yes |
Configuring library mode (build.lib) with DTS output | Yes |
| Setting up a standalone Vite project (no Nx) | No — use Vite docs directly |
| Adding a non-Vite bundler (esbuild standalone, Rollup) | No — this skill is Nx + Vite specific |
Preconditions:
Commands:
bunx nx add @nx/vite
bun add -d viteFramework plugin (choose one):
bun add -d @vitejs/plugin-react
# or
bun add -d @vitejs/plugin-vue
# or
bun add -d @sveltejs/vite-plugin-svelteExpected result:
@nx/vite and framework plugin installedPreconditions:
Recommended command:
bunx nx g @nx/vite:configuration <project-name>Manual baseline (vite.config.ts):
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
export default defineConfig({
root: __dirname,
plugins: [react(), nxViteTsPaths()],
});Expected result:
vite.config.ts exists and resolves workspace path aliasesPreconditions:
Ensure target config supports:
buildservetest (Vitest)Expected result:
nx run <project>:build and nx run <project>:test are valid targetsFor apps:
outDir and cacheDir relative to workspace rootnxCopyAssetsPlugin if non-public files must be copiedFor libraries:
build.librollupOptions.externalvite-plugin-dts for declaration outputExpected result:
dist/ with correct dependency boundariesCommands:
bunx nx run <project>:build
bunx nx run <project>:testExpected result:
nxViteTsPaths() in Nx MonoreposWhy:
@org/lib) fail without Nx path plugin integration.Bad:
export default defineConfig({
plugins: [react()],
});Good:
export default defineConfig({
plugins: [react(), nxViteTsPaths()],
});Why:
Bad:
build: {
lib: { entry: 'src/index.ts' },
}Good:
build: {
lib: { entry: 'src/index.ts' },
rollupOptions: {
external: ['react', 'react-dom', /^@my-org\//],
},
}Why:
Bad:
test: {
cache: { dir: './node_modules/.vitest' },
coverage: { reportsDirectory: './coverage' },
}Good:
test: {
cache: { dir: '../../node_modules/.vitest/apps/my-app' },
coverage: { reportsDirectory: '../../coverage/apps/my-app' },
}Why:
Bad:
Good:
build, server, test, plugins) and validate each step.nxViteTsPaths() in Nx monoreposroot: __dirnameoutDir and cacheDir relative to workspace roottest.reporters, test.environment, and deterministic cache/coverage pathses, cjs, umd) based on consumersskipDiagnostics: true/false) based on CI strategybunx nx run <project>:build
bunx nx run <project>:test
bunx @biomejs/biome check skills/nx-vite-integration/
bunx markdownlint-cli2 "skills/nx-vite-integration/**/*.md"@nx/vite executor options, inferred task configuration, and caching setupbuild.lib configuration, entry point patterns, and DTS generation