Nx comes with dedicated documentation for each framework:

Nx Plugin for React

The Nx Plugin for React contains generators for managing React applications and libraries within an Nx workspace. It provides:

  • Integration with libraries such as Jest, Cypress, and Storybook.
  • Scaffolding for state management with Redux Toolkit libraries.
  • Scaffolding for creating buildable libraries that can be published to npm.
  • Utilities for automatic workspace refactoring.

Adding the React plugin

Adding the React plugin to a workspace can be done with the following:

#yarn
yarn add -D @nrwl/react
#npm
npm install -D @nrwl/react

Note: You can create a new workspace that has React set up by doing npx create-nx-workspace@latest --preset=react

The file structure for a React application looks like:

myorg/
ā”œā”€ā”€ apps/
│   ā”œā”€ā”€ myapp/
│   │   ā”œā”€ā”€ src/
│   │   │   ā”œā”€ā”€ app/
│   │   │   ā”œā”€ā”€ assets/
│   │   │   ā”œā”€ā”€ environments/
│   │   │   ā”œā”€ā”€ favicon.ico
│   │   │   ā”œā”€ā”€ index.html
│   │   │   ā”œā”€ā”€ main.tsx
│   │   │   ā”œā”€ā”€ polyfills.ts
│   │   │   └── styles.css
│   │   ā”œā”€ā”€ browserslist
│   │   ā”œā”€ā”€ jest.config.js
│   │   ā”œā”€ā”€ tsconfig.app.json
│   │   ā”œā”€ā”€ tsconfig.json
│   │   └── tsconfig.spec.json
│   └── myapp-e2e/
│       ā”œā”€ā”€ src/
│       │   ā”œā”€ā”€ fixtures/
│       │   │   └── example.json
│       │   ā”œā”€ā”€ integration/
│       │   │   └── app.spec.ts
│       │   ā”œā”€ā”€ plugins/
│       │   │   └── index.ts
│       │   └── support/
│       │       ā”œā”€ā”€ app.po.ts
│       │       ā”œā”€ā”€ commands.ts
│       │       └── index.ts
│       ā”œā”€ā”€ cypress.json
│       ā”œā”€ā”€ tsconfig.e2e.json
│       └── tsconfig.json
ā”œā”€ā”€ libs/
ā”œā”€ā”€ tools/
ā”œā”€ā”€ README.md
ā”œā”€ā”€ workspace.json
ā”œā”€ā”€ nx.json
ā”œā”€ā”€ package.json
└── tsconfig.base.json

See Also

Executors / Builders

React applications are built using the executors from the @nrwl/web plugin.

  • build - Builds a web components application
  • dev-server - Builds and serves a web application
  • package - Bundles artifacts for a buildable library that can be distributed as an NPM package.

Generators