project.json:

1//... 2"my-app": { 3 "targets": { 4 //... 5 "build": { 6 "executor": "@nx/vite:build", 7 //... 8 //... 9 "options": { 10 "outputPath": "dist/apps/my-app" 11 }, 12 //... 13 } 14 }, 15 } 16} 17
Nx 15 and lower use @nrwl/ instead of @nx/
1nx serve my-app 2

Examples

Nx will automatically look in the root of your application for a vite.config.ts (or a vite.config.js) file. If you want to use a different path, you can set it in your project.json file, in the build target options:

1//... 2"my-app": { 3 "targets": { 4 //... 5 "build": { 6 "executor": "@nx/vite:build", 7 //... 8 "options": { 9 "outputPath": "dist/apps/my-app", 10 "configFile": "apps/my-app/vite.config.other-path.ts" 11 }, 12 "configurations": { 13 ... 14 } 15 }, 16 } 17} 18
Nx 15 and lower use @nrwl/ instead of @nx/

or even

1//... 2"my-app": { 3 "targets": { 4 //... 5 "build": { 6 "executor": "@nx/vite:build", 7 //... 8 "options": { 9 "outputPath": "dist/apps/my-app", 10 "configFile": "vite.config.base.ts" 11 }, 12 "configurations": { 13 ... 14 } 15 }, 16 } 17} 18
Nx 15 and lower use @nrwl/ instead of @nx/

Options

outputPath

string

The output path of the generated files.

buildLibsFromSource

boolean
Default: true

Read buildable libraries from source instead of building them separately.

base

baseHref
string

Base public path when served in development or production.

configFile

string

The name of the Vite.js configuration file.

cssCodeSplit

boolean

Enable/disable CSS code splitting. When enabled, CSS imported in async chunks will be inlined into the async chunk itself and inserted when the chunk is loaded.

emptyOutDir

boolean
Default: true

When set to false, outputPath will not be emptied during the build process.

fileReplacements

Default: []

Replace files with other files in the build.

force

boolean

Force the optimizer to ignore the cache and re-bundle

generatePackageJson

boolean

Generate a package.json for the build output.

includeDevDependenciesInPackageJson

boolean

Include devDependencies in the generated package.json.

logLevel

string
Accepted values: info, warn, error, silent

Adjust console output verbosity.

minify

oneOf [boolean, string]

Output sourcemaps. Use 'hidden' for use with error reporting tools without generating sourcemap comment.

manifest

oneOf [boolean, string]

Output sourcemaps. Use 'hidden' for use with error reporting tools without generating sourcemap comment.

mode

string

Mode to run the build in.

skipTypeCheck

boolean
Default: false

Skip type-checking via TypeScript. Skipping type-checking speeds up the build but type errors are not caught.

sourcemap

oneOf [boolean, string]

Output sourcemaps. Use 'hidden' for use with error reporting tools without generating sourcemap comment.

ssrManifest

oneOf [boolean, string]

When set to true, the build will also generate an SSR manifest for determining style links and asset preload directives in production. When the value is a string, it will be used as the manifest file name.

ssr

oneOf [boolean, string]

Produce SSR-oriented build. The value can be a string to directly specify the SSR entry, or true, which requires specifying the SSR entry via rollupOptions.input.

target

string

Browser compatibility target for the final bundle. For more info: https://vitejs.dev/config/build-options.html#build-target

watch

oneOf [boolean, object: object]
Default: false

Enable re-building when files change.