@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:

{ //... "targets": { //... "build": { "executor": "@nrwl/esbuild:esbuild", "options": { "main": "<app-root>", "tsConfig": "<app-root>/tsconfig.app.json", "outputPath": "dist/<app-root>" } } } }
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
"build": { "executor": "@nrwl/esbuild:esbuild", "options": { "main": "<app-root>", "tsConfig": "<app-root>/tsconfig.app.json", "outputPath": "dist/<app-root>", "format": ["esm", "cjs"] }

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

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.

deleteOutputPath

clean
boolean
Default: true

Remove previous output before build.

dependenciesFieldType

string
Default: dependencies
Accepted values: dependencies, peerDependencies

When bundleInternalProjectsOnly is true, this option determines whether external packages should be in 'dependencies' or 'peerDependencies' field in the generated package.json file.

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

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
boolean
Default: false

Generate sourcemap.

target

string
Default: esnext

The environment target for outputs.

thirdParty

boolean
Default: true

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

boolean
Default: false

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