@nrwl/esbuild:esbuild

Bundle a package for different platforms. Note: declaration (*.d.ts) file are not currently generated.

Options can be configured in project.json when defining the executor, or when invoking it. Read more about how to configure targets and executors here: https://nx.dev/reference/project-configuration#targets.

<app-root>/project.json:

1{
2  //...
3  "targets": {
4    //...
5    "build": {
6      "executor": "@nrwl/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
nx build <app-name>

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.

nx build <app-name> --format=cjs
nx build <app-name> --format=esm,cjs
nx build <app-name> # defaults to es# defaults to esm
1"build": {
2  "executor": "@nrwl/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

additionalEntryPoints

Array<string>
Default: []

List of additional entry points.

assets

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

List of static assets.

buildableProjectDepsInPackageJsonType

string
Default: peerDependencies
Accepted values: dependencies, peerDependencies

When updateBuildableProjectDepsInPackageJson is true, this adds dependencies to either peerDependencies or dependencies.

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'.

esbuildOptions

Additional options to pass to esbuild. See https://esbuild.github.io/api/.

format

f
Array<string>
Default: [esm]
Accepted values: esm, cjs

Set the output format(s).

main

entryFileRequired
string

The path to the entry file, relative to project.

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.

outputPath

Required
string

The output path of the generated files.

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.

project

string

The path to package.json file.

platform

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

Platform target for outputs.

sourcemap

sourceMap
boolean
Default: false

Generate sourcemap.

skipTypeCheck

boolean
Default: false

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

tsConfig

Required
string

The path to tsconfig file.

target

string
Default: esnext

The environment target for outputs.

updateBuildableProjectDepsInPackageJson

boolean
Default: true

Update buildable project dependencies in package.json.

watch

boolean
Default: false

Enable re-building when files change.

Additional Properties

anything

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