<app-root>/project.json:

1{ 2 //... 3 "targets": { 4 //... 5 "build": { 6 "executor": "@nx/esbuild:esbuild", 7 "options": { 8 "main": "<app-root>", 9 "tsConfig": "<app-root>/tsconfig.app.json", 10 "outputPath": "dist/<app-root>" 11 } 12 } 13 } 14} 15
1nx build <app-name> 2

Examples

The CommonJS format is required in some environments, such as Electron applications. By default, esbuild will use the ESM format, which is recommended for Web and Node applications. You may also output to multiple formats.

1nx build <app-name> --format=cjs 2nx build <app-name> --format=esm,cjs 3nx build <app-name> # defaults to es# defaults to esm 4
1"build": { 2 "executor": "@nx/esbuild:esbuild", 3 "options": { 4 "main": "<app-root>", 5 "tsConfig": "<app-root>/tsconfig.app.json", 6 "outputPath": "dist/<app-root>", 7 "format": ["esm", "cjs"] 8} 9

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.

esbuildOptions

Additional options to pass to esbuild. See https://esbuild.github.io/api/. Cannot be used with 'esbuildConfig' option.

esbuildConfig

string

Path to a esbuild configuration file. See https://esbuild.github.io/api/. Cannot be used with 'esbuildOptions' option.

additionalEntryPoints

Array<string>
Default: []

List of additional entry points.

assets

Array<oneOf [object , string]>
Default: []

List of static assets.

bundle

boolean
Default: true

Whether to bundle the main entry point and additional entry points. Set to false to keep individual output files.

declaration

boolean

Generate declaration (*.d.ts) files for every TypeScript or JavaScript file inside your project. Should be used for libraries that are published to an npm repository.

declarationRootDir

string

Sets the rootDir for the declaration (*.d.ts) files.

deleteOutputPath

clean
boolean
Default: true

Remove previous output before build.

external

Array<string>

Mark one or more module as external. Can use * wildcards, such as '*.png'.

format

f
Array<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).

generatePackageJson

boolean
Default: false

Generates a package.json and pruned lock file with the project's node_module dependencies populated for installing in a container. If a package.json exists in the project's directory, it will be reused with dependencies populated.

metafile

boolean
Default: false

Generate a meta.json file in the output folder that includes metadata about the build. This file can be analyzed by other tools.

minify

boolean
Default: false

Minifies outputs.

outputFileName

string

Name of the main output file. Defaults same basename as 'main' file.

outputHashing

string
Default: none
Accepted values: none, all

Define the output filename cache-busting hashing mode.

platform

string
Default: node
Accepted values: browser, node, neutral

Platform target for outputs.

sourcemap

sourceMap
oneOf [string, boolean]

Generate sourcemap.

target

string
Default: esnext

The environment target for outputs.

thirdParty

boolean

Includes third-party packages in the bundle (i.e. npm packages).

watch

boolean
Default: false

Enable re-building when files change.

Additional Properties

anything

Extra properties of any type may be provided to this object.

skipTypeCheck

Internal
boolean
Default: false

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