Skip to content

The React plugin for Nx, @nx/react, provides generators for applications and libraries, executors for Module Federation, and library build support. It integrates with popular bundlers and test runners so you can configure each project to match your team's toolchain.

You don't need the plugin to use React with Nx. Any project already benefits from caching, task orchestration, and the project graph. The plugin simplifies scaffolding and code generation.

Terminal window
nx add @nx/react
  1. Check that @nx/react is listed:

    Terminal window
    nx report
  2. Verify generators are available:

    Terminal window
    nx list @nx/react
Terminal window
npx create-nx-workspace@latest --template=nrwl/react-template
Terminal window
nx g @nx/react:app apps/my-app

To start the application in development mode, run nx serve my-app. Read more about the options available for the application generator.

The --bundler option selects the build tool for your application or buildable library. You can learn more about the specific bundler you scaffolded your project with on the bundler's plugin page:

Terminal window
nx g @nx/react:lib libs/my-lib
# With a bundler for buildable/publishable libraries
nx g @nx/react:lib libs/my-lib --bundler=vite
nx g @nx/react:lib libs/my-lib --bundler=rollup
nx g @nx/react:lib libs/my-lib --publishable --importPath=@myorg/my-lib

The same bundler options apply when creating buildable libraries. Read more about the options available for the library generator. You can also read more about buildable and publishable libraries.

Terminal window
nx serve my-app

This starts the development server with hot module replacement so you can iterate on your application locally.

Terminal window
nx build my-app
nx build my-lib

Build output goes to the dist folder by default. You can customize the output folder by setting outputPath in the project's configuration file.

Nx caches build results automatically. Subsequent builds of unchanged projects restore from cache.

To see the full configuration for a project:

Terminal window
nx show project my-app

Or open the project details view in Nx Console.

For full generator and executor option lists, see the generators reference and executors reference.

See Set Up CI for a complete CI configuration guide.

Terminal window
nx affected -t build test lint

This uses the project graph to determine which projects are affected by your changes and only runs tasks for those.

Share build and test cache results across your team and CI with remote caching:

Terminal window
nx connect