@nx/rollup:rollup

Packages a library for different web usages (ESM, CommonJS).

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.

To include dependencies in the output package.json, the dependencies must be installed as a dependencies in the root package.json

package.json
{ "dependencies": { "some-dependency": "^1.0.0" } }

To have dependencies in the be listed in the final package.json of your project, set the updateBuildableProjectDepsInPackageJson option to true. After than dependencies will be added to the peerDependencies field of the output package.json. You can use buildableProjectDepsInPackageJsonType option to change which field the dependencies are output to.

project.json
{ "targets": { "build": { "executor": "@nx/rollup:rollup", "options": { "buildableProjectDepsInPackageJsonType": "dependencies", "updateBuildableProjectDepsInPackageJson": true } } } }
Nx 15 and lower use @nrwl/ instead of @nx/

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.

project

string

The path to package.json file.

allowJs

boolean
Default: false

Allow JavaScript files to be compiled.

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.

babelUpwardRootMode

boolean
Default: false

Whether to set rootmode to upward. See https://babeljs.io/docs/en/options#rootmode

compiler

string
Default: babel
Accepted values: babel, swc, tsc

Which compiler to use.

deleteOutputPath

boolean
Default: true

Delete the output path before building.

external

oneOf [string, Array<string>]

A list of external modules that will not be bundled (react, react-dom, etc.). Can also be set to all (bundle nothing) or none (bundle everything).

extractCss

boolean ∪ string
Default: true

CSS files will be extracted to the output folder. Alternatively custom filename can be provided (e.g. styles.css)

format

f
Array<string>
Accepted values: esm, cjs

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

generateExportsField

boolean
Default: false

Generate package.json with 'exports' field. This field defines entry points in the package and is used by Node and the TypeScript compiler.

javascriptEnabled

boolean
Default: false

Sets javascriptEnabled option for less loader

outputFileName

string

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

rollupConfig

oneOf [Array<string>, string]

Path to a function which takes a rollup config and returns an updated rollup config.

skipTypeCheck

boolean
Default: false

Whether to skip TypeScript type checking.

updateBuildableProjectDepsInPackageJson

boolean
Default: true

Update buildable project dependencies in package.json.

watch

boolean
Default: false

Enable re-building when files change.