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.
Setting Up @nx/react
Section titled “Setting Up @nx/react”Add to an Existing Nx Workspace
Section titled “Add to an Existing Nx Workspace”nx add @nx/reactVerification
Section titled “Verification”Check that
@nx/reactis listed:Terminal window nx reportVerify generators are available:
Terminal window nx list @nx/react
Create a New Workspace
Section titled “Create a New Workspace”npx create-nx-workspace@latest --template=nrwl/react-templateGenerate a New Application
Section titled “Generate a New Application”nx g @nx/react:app apps/my-appTo start the application in development mode, run nx serve my-app. Read more about the options available for the application generator.
Choose a Bundler
Section titled “Choose a Bundler”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:
Generate a New Library
Section titled “Generate a New Library”nx g @nx/react:lib libs/my-lib
# With a bundler for buildable/publishable librariesnx g @nx/react:lib libs/my-lib --bundler=vitenx g @nx/react:lib libs/my-lib --bundler=rollupnx g @nx/react:lib libs/my-lib --publishable --importPath=@myorg/my-libThe 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.
Serve Applications
Section titled “Serve Applications”nx serve my-appThis starts the development server with hot module replacement so you can iterate on your application locally.
Build Projects
Section titled “Build Projects”nx build my-appnx build my-libBuild 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.
View Project Configuration
Section titled “View Project Configuration”To see the full configuration for a project:
nx show project my-appOr open the project details view in Nx Console.
For full generator and executor option lists, see the generators reference and executors reference.
CI Considerations
Section titled “CI Considerations”See Set Up CI for a complete CI configuration guide.
Build and Test Only What Changed
Section titled “Build and Test Only What Changed”nx affected -t build test lintThis uses the project graph to determine which projects are affected by your changes and only runs tasks for those.
Remote Caching
Section titled “Remote Caching”Share build and test cache results across your team and CI with remote caching:
nx connect