Examples

@nx/js:swc can inline non-buildable libraries by opt-in to Inlining mode with external option.

libs/ts-lib/project.json
1{ 2 "build": { 3 "executor": "@nx/js:swc", 4 "options": { 5 "outputPath": "dist/libs/ts-lib", 6 "main": "libs/ts-lib/src/index.ts", 7 "tsConfig": "libs/ts-lib/tsconfig.lib.json", 8 "assets": ["libs/ts-lib/*.md"], 9 "external": "all" 10 } 11 } 12} 13
Nx 15 and lower use @nrwl/ instead of @nx/

npx nx build ts-lib --external=all

@nx/js:swc can also inline buildable libraries by setting external: 'none'

libs/ts-lib/project.json
1{ 2 "build": { 3 "executor": "@nx/js:swc", 4 "options": { 5 "outputPath": "dist/libs/ts-lib", 6 "main": "libs/ts-lib/src/index.ts", 7 "tsConfig": "libs/ts-lib/tsconfig.lib.json", 8 "assets": ["libs/ts-lib/*.md"], 9 "external": "none" 10 } 11 } 12} 13
Nx 15 and lower use @nrwl/ instead of @nx/

npx nx build ts-lib --external=none

Options

main

Required
string

The name of the main entry-point file.

outputPath

Required
string

The output path of the generated files.

tsConfig

Required
string

The path to the Typescript configuration file.

additionalEntryPoints

Array<string>

Additional entry-points to add to exports field in the package.json file.

generateExportsField

exports
boolean
Default: false

Update the output package.json file's 'exports' field. This field is used by Node and bundles.

skipTypeCheck

boolean
Default: false

Whether to skip TypeScript type checking.

assets

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

List of static assets.

clean

boolean
Default: true

Remove previous output before build.

external

oneOf [string, Array<string>]

A list projects to be treated as external. This feature is experimental

externalBuildTargets

Array<string>
Default: [build]

List of target names that annotate a build target for a project

swcrc

string

The path to the SWC configuration file. Default: .swcrc

swcExclude

Hidden
Array<anything>
Default: [./src/**/.*.spec.ts$,./**/.*.spec.ts$,./src/**/jest-setup.ts$,./**/jest-setup.ts$,./**/.*.js$]

List of SWC Glob/Regex to be excluded from compilation (https://swc.rs/docs/configuration/compilation#exclude).

watch

boolean
Default: false

Enable re-building when files change.

generateLockfile

boolean
Default: false

Generate a lockfile (e.g. package-lock.json) that matches the workspace lockfile to ensure package versions match.

buildableProjectDepsInPackageJsonType

Deprecated
string
Default: peerDependencies
Accepted values: dependencies, peerDependencies

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

Configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17.

updateBuildableProjectDepsInPackageJson

Deprecated
boolean
Default: false

Whether to update the buildable project dependencies in the build output package.json.

Configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17.