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
- application - Create an React application
- component - Create an React component
- library - Create an React library
- redux - Generate a Redux slice for a project
- storybook-configuration - Set up Storybook for a react library