project.json:

{ "name": "api", //... "targets": { "build": { "dependsOn": [ { "projects": "self", "target": "build-api", "params": "forward" } ], "executor": "@nx/js:generate-package-json", "options": { "outputPath": "dist/apps/api", "main": "apps/api/src/main.ts", "tsConfig": "apps/api/tsconfig.app.json" } }, "build-api": { "executor": "@nx/vite:build", //... "configurations": { "production": { "mode": "production" } } }, "serve": { "executor": "@nx/vite:dev-server", //... "configurations": { "production": { "buildTarget": "api:build:production" } } } } }
Nx 15 and lower use @nrwl/ instead of @nx/
nx build api --prod nx build api --dev

Options

main

entryFileRequired
string

The path to the entry file, relative to project.

outputPath

Required
string

The output path of the generated files.

tsConfig

Required
string

The path to tsconfig file.

buildableProjectDepsInPackageJsonType

string
Default: dependencies
Accepted values: dependencies, devDependencies

The type of dependency to use for buildable project dependencies in the generated package.json.

excludeLibsInPackageJson

boolean
Default: true

Exclude libraries in the package.json file. This is useful if you are using a package.json file in the project's directory.

format

f
string
Default: esm
Accepted values: esm, cjs

List of module formats to output. Defaults to matching format from tsconfig (e.g. CJS for CommonJS, and ESM otherwise).

generateLockfile

boolean
Default: true

Generate a lock file for the generated package.json.