diff --git a/docs/shared/tutorials/react-monorepo.md b/docs/shared/tutorials/react-monorepo.md index c87f48975d..4f894ecccf 100644 --- a/docs/shared/tutorials/react-monorepo.md +++ b/docs/shared/tutorials/react-monorepo.md @@ -48,8 +48,6 @@ title="Nx React Monorepo Tutorial Walkthrough" ## Creating a new React Monorepo -{% video-link link="https://youtu.be/gc4N7kxiA50?t=66" /%} - Create a new React monorepo with the following command: ```{% command="npx create-nx-workspace@latest react-monorepo --preset=react-monorepo" path="~" %} @@ -59,7 +57,7 @@ NX Let's create a new workspace [https://nx.dev/getting-started/intro] ✔ Application name · react-store ✔ Which bundler would you like to use? · vite ✔ Which unit test runner would you like to use? · vitest -✔ Test runner to use for end to end (E2E) tests · cypress +✔ Test runner to use for end to end (E2E) tests · playwright ✔ Default stylesheet format · css ✔ Would you like to use ESLint? · Yes ✔ Would you like to use Prettier for code formatting? · Yes @@ -70,7 +68,6 @@ Let's name the initial application `react-store`. In this tutorial we're going t ``` └─ react-monorepo - ├─ ... ├─ apps │ ├─ react-store │ │ ├─ public @@ -92,12 +89,15 @@ Let's name the initial application `react-store`. In this tutorial we're going t │ │ └─ vite.config.ts │ └─ react-store-e2e │ └─ ... + ├─ ... + ├─ package.json ├─ nx.json ├─ tsconfig.base.json - └─ package.json + ├─ tsconfig.json + └─ vitest.workspace.ts ``` -The setup includes.. +The setup includes: - a new React application (`apps/react-store/`) - a Playwright based set of e2e tests (`apps/react-store-e2e/`) @@ -111,8 +111,6 @@ The [`nx.json` file](/reference/nx-json) contains configuration settings for Nx ## Serving the App -{% video-link link="https://youtu.be/gc4N7kxiA50?t=120" /%} - To serve your new React application, just run: ```shell @@ -127,8 +125,6 @@ Nx uses the following syntax to run tasks: ### Inferred Tasks -{% video-link link="https://youtu.be/gc4N7kxiA50?t=158" /%} - Nx identifies available tasks for your project from [tooling configuration files](/concepts/inferred-tasks), `package.json` scripts and the targets defined in `project.json`. To view the tasks that Nx has detected, look in the [Nx Console](/getting-started/editor-setup) project detail view or run: ```shell @@ -245,37 +241,36 @@ export default defineConfig({ ## Add Another Application -{% video-link link="https://youtu.be/gc4N7kxiA50?t=259" /%} - Nx plugins usually provide [generators](/features/generate-code) that allow you to easily scaffold code, configuration or entire projects. To see what capabilities the `@nx/react` plugin provides, run the following command and inspect the output: ```{% command="npx nx list @nx/react" path="react-monorepo" %} NX Capabilities in @nx/react: - GENERATORS +GENERATORS - init : Initialize the `@nx/react` plugin. - application : Create a React application. - library : Create a React library. - component : Create a React component. - redux : Create a Redux slice for a project. - storybook-configuration : Set up storybook for a React app or library. - component-story : Generate storybook story for a React component - stories : Create stories/specs for all components declared in an app or library. - hook : Create a hook. - cypress-component-configuration : Setup Cypress component testing for a React project - component-test : Generate a Cypress component test for a React component - setup-tailwind : Set up Tailwind configuration for a project. - setup-ssr : Set up SSR configuration for a project. - host : Generate a host react application - remote : Generate a remote react application - federate-module : Federate a module. +init : Initialize the `@nx/react` plugin. +application : Create a React application. +library : Create a React library. +component : Create a React component. +redux : Create a Redux slice for a project. +storybook-configuration : Set up storybook for a React app or library. +component-story : Generate storybook story for a React component +stories : Create stories/specs for all components declared in an app or library. +hook : Create a hook. +host : Generate a host react application +remote : Generate a remote react application +cypress-component-configuration : Setup Cypress component testing for a React project +component-test : Generate a Cypress component test for a React component +setup-tailwind : Set up Tailwind configuration for a project. +setup-ssr : Set up SSR configuration for a project. +federate-module : Federate a module. - EXECUTORS/BUILDERS +EXECUTORS/BUILDERS - module-federation-dev-server : Serve a host or remote application. - module-federation-ssr-dev-server : Serve a host application along with it's known remotes. +module-federation-dev-server : Serve a host or remote application. +module-federation-ssr-dev-server : Serve a host application along with it's known remotes. +module-federation-static-server : Serve a host and its remotes statically. ``` {% callout type="info" title="Prefer a more visual UI?" %} @@ -291,9 +286,9 @@ Run the following command to generate a new `inventory` application. Note how we ```{% command="npx nx g @nx/react:app apps/inventory" path="react-monorepo" %} NX Generating @nx/react:application -✔ Would you like to add React Router to this application? (y/N) · false +✔ Would you like to add routing to this application? (y/N) · false ✔ What unit test runner should be used? · vitest -✔ Which E2E test runner would you like to use? · cypress +✔ Which E2E test runner would you like to use? · playwright CREATE apps/inventory/index.html CREATE apps/inventory/public/favicon.ico CREATE apps/inventory/src/app/app.spec.tsx @@ -306,19 +301,15 @@ CREATE apps/inventory/src/app/app.tsx CREATE apps/inventory/src/styles.css CREATE apps/inventory/tsconfig.json CREATE apps/inventory/package.json +CREATE apps/inventory/eslint.config.mjs UPDATE nx.json CREATE apps/inventory/tsconfig.spec.json CREATE apps/inventory/vite.config.ts -CREATE apps/inventory/eslint.config.mjs CREATE apps/inventory-e2e/package.json -CREATE apps/inventory-e2e/src/e2e/app.cy.ts -CREATE apps/inventory-e2e/src/support/app.po.ts -CREATE apps/inventory-e2e/src/support/e2e.ts -CREATE apps/inventory-e2e/src/fixtures/example.json -CREATE apps/inventory-e2e/src/support/commands.ts -CREATE apps/inventory-e2e/cypress.config.ts -CREATE apps/inventory-e2e/tsconfig.json +CREATE apps/inventory-e2e/src/example.spec.ts +CREATE apps/inventory-e2e/playwright.config.ts UPDATE tsconfig.json +CREATE apps/inventory-e2e/tsconfig.json CREATE apps/inventory-e2e/eslint.config.mjs NOTE: The "dryRun" flag means no changes were made. @@ -332,8 +323,6 @@ npx nx g @nx/react:app apps/inventory ## Share Code with Local Libraries -{% video-link link="https://youtu.be/gc4N7kxiA50?t=324" /%} - When you develop your React application, usually all your logic sits in the `app` folder. Ideally separated by various folder names which represent your "domains". As your app grows, however, the app becomes more and more monolithic and the code is unable to be shared with other applications. ``` @@ -367,8 +356,6 @@ Nx allows you to separate this logic into "local libraries". The main benefits i ### Create Local Libraries -{% video-link link="https://youtu.be/gc4N7kxiA50?t=366" /%} - Let's assume our domain areas include `products`, `orders` and some more generic design system components, called `ui`. We can generate a new library for each of these areas using the React library generator: ``` @@ -426,8 +413,6 @@ Each of these libraries ### Import Libraries into the React Applications -{% video-link link="https://youtu.be/gc4N7kxiA50?t=456" /%} - All libraries that we generate are automatically included in the `workspaces` defined in the root-level `package.json`. ```json {% fileName="package.json" %} @@ -509,7 +494,7 @@ import { Route, Routes } from 'react-router-dom'; import { Products } from '@react-monorepo/products'; function Home() { - return