Skip to content

Rollup is a module bundler for JavaScript libraries and applications. In a Rollup monorepo, Nx builds and caches projects across your workspace and rebuilds only what a change affects.

The Nx Plugin for Rollup contains executors and generators that support building applications with Rollup.

The @nx/rollup plugin supports the following package versions.

PackageSupported Versions
rollup^3.0.0 || ^4.0.0

Nx generators install the latest supported versions automatically when scaffolding new projects.

In any Nx workspace, you can install @nx/rollup by running the following command:

Terminal window
nx add @nx/rollup

This will install the correct version of @nx/rollup.

The @nx/rollup/plugin plugin looks for these Rollup configuration files:

  • rollup.config.js
  • rollup.config.cjs
  • rollup.config.mjs
  • rollup.config.ts
  • rollup.config.cts
  • rollup.config.mts

A configuration file is associated with a project when its directory also contains a package.json or project.json. Nx creates a cached build task that runs rollup -c, with outputs based on your Rollup configuration, and depends on the same task in dependency projects.

Configure the plugin in nx.json:

nx.json
{
"plugins": [
{
"plugin": "@nx/rollup/plugin",
"options": {
"buildTargetName": "build",
"buildDepsTargetName": "build-deps",
"watchDepsTargetName": "watch-deps"
}
}
]
}
OptionTypeDefaultDescription
buildTargetNamestringbuildName of the cached Rollup build task.
buildDepsTargetNamestringbuild-depsName of the task that builds project dependencies.
watchDepsTargetNamestringwatch-depsName of the task that watches project dependencies.

Use include and exclude glob patterns on the plugin entry to scope inference. A target defaults plugin filter must use the exact identifier @nx/rollup/plugin.

You can generate a new library that uses Rollup with the following command:

Terminal window
nx g @nx/js:lib mylib --bundler=rollup

This will create a new library configured to use Rollup for building.

In CI, Nx runs nx affected to rebuild and retest only the projects a change touches, and caches results to skip repeated work.

For a complete pipeline, see Set up CI.