### Setup Node.js and Install Dependencies Source: https://nx.dev/docs/guides/adopting-nx/adding-to-existing-project Sets up the specified Node.js version and configures npm caching. Then, it installs project dependencies using `npm ci`. ```yaml - uses: actions/setup-node@v3 with: node-version: 20 cache: 'npm' - run: npm ci ``` -------------------------------- ### Full Nx Cloud Launch Template Example Source: https://nx.dev/docs/reference/nx-cloud/launch-template-examples This example demonstrates a comprehensive launch template configuration, including common JavaScript initialization steps and Rust-specific setup. It utilizes YAML anchors for reusability and defines multiple agent templates for different resource classes. ```yaml // ./nx/workflows/agents.yaml # Define common setup steps that can be reused across templates common-js-init-steps: &common-js-init-steps # using a reusable step in an external GitHub repo, # this step is provided by Nx Cloud: https://github.com/nrwl/nx-cloud-workflows/tree/main/workflow-steps - name: Checkout uses: 'nrwl/nx-cloud-workflows/v6/workflow-steps/checkout/main.yaml' - name: Restore Node Modules Cache uses: 'nrwl/nx-cloud-workflows/v6/workflow-steps/cache/main.yaml' # the cache step requires configuration via env vars # https://github.com/nrwl/nx-cloud-workflows/tree/main/workflow-steps/cache#options inputs: # Include patches directories to ensure cache is busted when patches change # If you use a custom patches directory, add it to the key as well key: 'package-lock.json|yarn.lock|pnpm-lock.yaml|patches/**|.yarn/patches/**' paths: | ~/.npm # or ~/.cache/yarn # or ~/.local/share/pnpm/store base-branch: 'main' - name: Restore Browser Binary Cache uses: 'nrwl/nx-cloud-workflows/v6/workflow-steps/cache/main.yaml' inputs: key: 'package-lock.json|yarn.lock|pnpm-lock.yaml|"browsers"' paths: | '~/.cache/Cypress' base-branch: 'main' - name: Install Node Modules uses: 'nrwl/nx-cloud-workflows/v6/workflow-steps/install-node-modules/main.yaml' - name: Install Browsers (if needed) uses: 'nrwl/nx-cloud-workflows/v6/workflow-steps/install-browsers/main.yaml' # You can also run a custom script to configure various things on the agent machine - name: Run a custom script script: | git config --global user.email test@test.com git config --global user.name "Test Test" - name: Define Step Env Var # this env var will be available to all future steps using these 'common-init-steps' reusable steps # persist env vars between steps by writing to the $NX_CLOUD_ENV file script: | echo "MY_STEP_ENV=step-env-var" >> $NX_CLOUD_ENV common-rust-init-steps: &common-rust-init-steps - name: Checkout uses: 'nrwl/nx-cloud-workflows/v6/workflow-steps/checkout/main.yaml' # add Rust-specific steps - name: Install Rust script: | curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh -s -- -y source "$HOME/.cargo/env" rustup toolchain install stable # persist cargo bin into PATH echo "PATH=$HOME/.cargo/bin:$PATH" >> $NX_CLOUD_ENV launch-templates: # Custom template name, the name is referenced via --distribute-on="3 my-linux-medium-js" # You can define as many templates as you need, commonly used to make different sizes or toolchains depending on your workspace needs my-linux-medium-js: resource-class: 'docker_linux_amd64/medium' image: 'ubuntu22.04-node24.14-v1' # Define environment variables shared among all steps in this launch template env: MY_ENV_VAR: shared # list out steps to run on the agent before accepting tasks # the agent will need a copy of the source code and dependencies installed # note we are using yaml anchors to reduce duplication with the below launch-template (they have the same init-steps) init-steps: *common-js-init-steps # another template which does the same as above, but with a large resource class # You're not required to define a template for every resource class, only define what you need! my-linux-large-js: resource-class: 'docker_linux_amd64/large' image: 'ubuntu22.04-node24.14-v1' env: MY_ENV_VAR: shared # note we are using yaml anchors to reduce duplication with the above launch-template (they have the same init-steps) init-steps: *common-js-init-steps # template that installs rust my-linux-rust-large: resource-class: 'docker_linux_amd64/large' image: 'ubuntu22.04-node24.14-v1' init-steps: *common-rust-init-steps ``` -------------------------------- ### Initialize Nx Workspace Source: https://nx.dev/docs/getting-started/start-new-project Use the interactive CLI command to scaffold a new monorepo with guided setup options. ```shell npx create-nx-workspace@latest ``` ```shell npx create-nx-workspace@latest --template=nrwl/empty-template ``` -------------------------------- ### Set up an Nx workspace Source: https://nx.dev/docs/getting-started/tutorials/crafting-your-workspace Use this prompt to guide an AI agent in setting up an Nx workspace. It handles existing workspaces, fresh setups with `create-nx-workspace`, and initializing Nx in existing projects with `nx init`. It also includes verification steps. ```bash npx create-nx-workspace ``` ```bash nx init ``` ```bash cat nx.json ``` -------------------------------- ### Manage local registry and package lifecycle Source: https://nx.dev/docs/extending-nx/create-install-package Commands to start the local registry, build/publish packages to it, and execute the create-package command for testing. ```shell npx nx local-registry npx nx run-many --targets build npx nx release version 1.0.0 npx nx release publish --tag latest npx create-my-plugin test-workspace ``` -------------------------------- ### GitHub Actions CI Workflow with Bun and Mise Source: https://nx.dev/docs/guides/nx-cloud/use-bun An example GitHub Actions workflow that uses `mise-action` to set up Node and Bun, installs dependencies with `bun install --frozen-lockfile`, and runs Nx commands. Note that `nx start-ci-run` uses `npx` as dependencies are not yet installed. ```yaml // .github/workflows/ci.yml name: CI on: push: branches: - main pull_request: permissions: actions: read contents: read env: NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} jobs: main: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 with: fetch-depth: 0 filter: tree:0 - run: npx nx start-ci-run --distribute-on="5 linux-large" --stop-agents-after="e2e" - name: Setup toolchains with mise uses: jdx/mise-action@v3 - name: Install dependencies run: bun install --frozen-lockfile - uses: nrwl/nx-set-shas@v5 - run: bunx nx record -- nx format:check - run: bunx nx run-many -t lint test build - run: bunx nx run-many -t e2e - name: Self-healing run: bunx nx fix-ci if: always() ``` -------------------------------- ### Previous Local Registry Setup Script Source: https://nx.dev/docs/guides/nx-release/update-local-registry-setup This script starts a local registry and publishes packages using `nx run-many`. Update this if you are using an older Nx version. ```typescript /** * This script starts a local registry for e2e testing purposes. * It is meant to be called in jest's globalSetup. */ import { startLocalRegistry } from '@nx/js/plugins/jest/local-registry'; import { execFileSync } from 'child_process'; export default async () => { // local registry target to run const localRegistryTarget = '@demo-plugin-1800/source:local-registry'; // storage folder for the local registry const storage = './tmp/local-registry/storage'; global.stopLocalRegistry = await startLocalRegistry({ localRegistryTarget, storage, verbose: false, }); const nx = require.resolve('nx/bin/nx'); execFileSync( nx, ['run-many', '--targets', 'publish', '--ver', '0.0.0-e2e', '--tag', 'e2e'], { env: process.env, stdio: 'inherit' } ); }; ``` -------------------------------- ### Install System Packages with apt Source: https://nx.dev/docs/reference/nx-cloud/launch-template-examples Use the 'apt' package manager within an init-step to install common Linux packages like the GitHub CLI. This streamlines toolchain setup for your workspace. ```yaml // ./nx/workflows/agents.yaml launch-templates: my-linux-medium-js: resource-class: 'docker_linux_amd64/medium' image: 'ubuntu22.04-node24.14-v1' init-steps: - name: Install Extras script: | sudo apt install gh unzip zip -y ``` -------------------------------- ### Navigate and Install Dependencies Source: https://nx.dev/docs/getting-started/tutorials/angular-monorepo-tutorial After creating the workspace, change into the directory and install all necessary project dependencies. ```bash cd my-nx-repo npm install ``` -------------------------------- ### Updated Local Registry Setup Script with Nx Release Source: https://nx.dev/docs/guides/nx-release/update-local-registry-setup This script starts a local registry and publishes packages using Nx Release functions. This is the recommended approach for newer Nx versions. ```typescript /** * This script starts a local registry for e2e testing purposes. * It is meant to be called in jest's globalSetup. */ import { startLocalRegistry } from '@nx/js/plugins/jest/local-registry'; import { execFileSync } from 'child_process'; import { releasePublish, releaseVersion } from 'nx/release'; export default async () => { // local registry target to run const localRegistryTarget = '@demo-plugin-1800/source:local-registry'; // storage folder for the local registry const storage = './tmp/local-registry/storage'; global.stopLocalRegistry = await startLocalRegistry({ localRegistryTarget, storage, verbose: false, }); await releaseVersion({ specifier: '0.0.0-e2e', stageChanges: false, gitCommit: false, gitTag: false, firstRelease: true, versionActionsOptionsOverrides: { skipLockFileUpdate: true, }, }); await releasePublish({ tag: 'e2e', firstRelease: true, }); }; ``` -------------------------------- ### Start CI Run with Static Agent Allocation Source: https://nx.dev/docs/features/ci-features/dynamic-agents This command starts a CI run with a fixed number and type of agents. Use this for simpler setups or when dynamic scaling is not required. ```bash npx nx start-ci-run --distribute-on="8 linux-medium-js" --stop-agents-after="e2e-ci" ``` -------------------------------- ### NxAppWebpackPlugin Configuration Example Source: https://nx.dev/docs/technologies/build-tools/webpack/guides/webpack-plugins Example demonstrating how to configure NxAppWebpackPlugin within a Webpack setup. It specifies the main entry point, tsconfig file, index HTML, styles, output hashing, and optimization settings. ```javascript const { NxAppWebpackPlugin } = require('@nx/webpack/app-plugin'); const { join } = require('path'); module.exports = { output: { path: join(__dirname, '../../dist/apps/demo'), }, devServer: { port: 4200, }, plugins: [ new NxAppWebpackPlugin({ main: './src/main.ts', tsConfig: './tsconfig.app.json', index: './src/index.html', styles: ['./src/styles.css'], outputHashing: process.env['NODE_ENV'] === 'production' ? 'all' : 'none', optimization: process.env['NODE_ENV'] === 'production', }), ], }; ``` -------------------------------- ### Install Nx Plugin Source: https://nx.dev/docs/extending-nx/publish-plugin After publishing, install your plugin in other workspaces using the `nx add` command. ```shell nx add nx-cfonts ``` -------------------------------- ### Start Nx MCP server Source: https://nx.dev/docs/reference/nx-commands Starts the Nx MCP server. ```bash nx mcp ``` -------------------------------- ### Example ESLint Configuration Source: https://nx.dev/docs/technologies/angular/migrations An example of an .eslintrc.json file structure after the migration has been applied. ```json { "overrides": [ { "files": ["*.html"], "rules": { "some-rule-for-html": "error" } }, { "files": ["*.ts"], "rules": { "@angular-eslint/prefer-standalone": "off" } } ] } ``` -------------------------------- ### List installed plugins Source: https://nx.dev/docs/reference/nx-commands Lists all plugins currently installed in the Nx workspace. ```bash nx list ``` -------------------------------- ### Implement Generator Logic Source: https://nx.dev/docs/extending-nx/local-generators Example of a generator entry point using @nx/devkit. It manipulates the virtual file system tree and can trigger post-generation tasks like package installation. ```typescript import { Tree, formatFiles, installPackagesTask } from '@nx/devkit'; import { libraryGenerator } from '@nx/js'; export default async function (tree: Tree, schema: any) { await libraryGenerator(tree, { name: schema.name }); await formatFiles(tree); return () => { installPackagesTask(tree); }; } ``` -------------------------------- ### Verify @nx/react Installation Source: https://nx.dev/docs/technologies/react/introduction Check if the @nx/react plugin is installed and list its available generators. This confirms successful setup. ```bash nx report ``` ```bash nx list @nx/react ``` -------------------------------- ### Install Compatible NPM Packages with Nx Source: https://nx.dev/docs/technologies/react/expo/introduction Install packages compatible with the current version of Expo. This command ensures that installed packages work correctly with your Expo setup. ```bash nx install ``` ```bash nx install --packages= ``` ```bash nx install --packages=,, ``` -------------------------------- ### Full nx.json Configuration Example Source: https://nx.dev/docs/reference/nx-json This example shows all available options in nx.json. Your actual configuration will likely be much shorter. ```json // nx.json { "plugins": [ { "plugin": "@nx/eslint/plugin", "options": { "targetName": "lint" } } ], "parallel": 4, "cacheDirectory": "tmp/my-nx-cache", "defaultBase": "main", "namedInputs": { "default": ["{projectRoot}/**/*"], "production": ["!{projectRoot}/**/*.spec.tsx"] }, "targetDefaults": { "@nx/js:tsc": { "inputs": ["production", "^production"], "dependsOn": ["^build"], "options": { "main": "{projectRoot}/src/index.ts" }, "cache": true }, "test": { "cache": true, "inputs": ["default", "^production", "{workspaceRoot}/jest.preset.js"], "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], "executor": "@nx/jest:jest" } }, "release": { "version": { "conventionalCommits": true }, "changelog": { "git": { "commit": true, "tag": true }, "workspaceChangelog": { "createRelease": "github" }, "projectChangelogs": true } }, "sync": { "globalGenerators": ["my-plugin:my-sync-generator"] }, "generators": { "@nx/js:library": { "buildable": true } }, "extends": "nx/presets/npm.json", "tui": { "enabled": true, "autoExit": true }, "conformance": { "rules": [ { "rule": "@nx/conformance/enforce-module-boundaries", "status": "evaluated" }, { "rule": "./tools/local-conformance-rules/check-project.ts", "projects": ["*"] } ] }, "analytics": true } ``` -------------------------------- ### Install AWS CLI Manually Source: https://nx.dev/docs/reference/nx-cloud/launch-template-examples Manually install the AWS CLI using official directions, which requires the 'unzip' package. This method is useful for custom installation setups and includes verification steps for authentication. ```yaml // ./nx/workflows/agents.yaml launch-templates: my-linux-medium-js: resource-class: 'docker_linux_amd64/medium' image: 'ubuntu22.04-node24.14-v1' init-steps: # step assumes you've passed all required AWS_* environment variables from the main agent via --with-env-vars - name: Install AWS CLI script: | # unzip is required to unzip the AWS CLI installer sudo apt install gh unzip -y curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" unzip awscliv2.zip # run installer, default location is already in the PATH # if installing in a custom location, # then update the $PATH like `PATH=$PATH:[extra-path-items] >> $NX_CLOUD_ENV` sudo ./aws/install # print AWS CLI version to verify command is avaiable aws --version # verify credentials to AWS is working aws sts get-caller-identity ``` -------------------------------- ### Run development server Source: https://nx.dev/docs/technologies/angular/guides/nx-and-angular Starts the development server using the Nx CLI. ```shell npx nx serve ``` -------------------------------- ### Initialize Nx in Existing Project Source: https://nx.dev/docs/guides/adopting-nx/adding-to-existing-project Run the Nx init command in the root of your existing project to set up Nx. This command analyzes your project and installs necessary Nx packages. ```bash npx nx init ``` -------------------------------- ### Setup Docker Buildx in CI Source: https://nx.dev/docs/features/ci-features/docker-layer-caching Integrate this step into your CI workflow's init-steps to ensure BuildKit is available before Docker builds commence. ```yaml - name: Setup Docker Buildx uses: 'nrwl/nx-cloud-workflows/main/workflow-steps/setup-docker-buildx/main.yaml' ``` -------------------------------- ### Serve a project using the file-server executor Source: https://nx.dev/docs/reference/web/executors Command to serve the 'myapp' project using the configured file-server executor. ```bash nx serve myapp ``` -------------------------------- ### Use a Reusable Step in Init-Steps Source: https://nx.dev/docs/reference/nx-cloud/launch-templates Specifies an existing step file to be used as an init-step. Cannot be used with 'script'. Provides a way to reuse common setup tasks. ```yaml // .nx/workflows/agents.yaml launch-templates: template-one: init-steps: - uses: 'nrwl/nx-cloud-workflows/v6/workflow-steps/checkout/main.yaml' - name: 'Install Node Modules' uses: 'nrwl/nx-cloud-workflows/v6/workflow-steps/install-node-modules/main.yaml' ``` -------------------------------- ### Verify @nx/next Plugin Setup Source: https://nx.dev/docs/technologies/react/next/introduction Check if the @nx/next plugin is correctly installed and configured in your Nx workspace by reporting its status and verifying inferred targets. ```bash nx report ``` ```bash nx show projects --with-target=build ``` ```bash nx show project my-next-app ``` -------------------------------- ### GET /devkit/getPackageManagerCommand Source: https://nx.dev/docs/reference/devkit/getPackageManagerCommand Retrieves the appropriate package manager commands (install, add, etc.) based on the workspace configuration or explicit input. ```APIDOC ## GET /devkit/getPackageManagerCommand ### Description Returns the set of commands associated with the detected or specified package manager. This is useful for executing package manager operations programmatically within an Nx workspace. ### Method GET ### Endpoint getPackageManagerCommand(packageManager?, root?) ### Parameters #### Path Parameters - **packageManager** (PackageManager) - Optional - The package manager to use. If not provided, it will be detected based on the lock file. - **root** (string) - Optional - The directory the commands will be ran inside of. Defaults to the current workspace's root. ### Request Example ```javascript getPackageManagerCommand('npm', './my-project'); ``` ### Response #### Success Response (200) - **PackageManagerCommands** (Object) - An object containing command strings for the package manager (e.g., add, addDev, install). #### Response Example { "add": "npm install", "addDev": "npm install -D", "install": "npm install" } ``` -------------------------------- ### Run nx-cloud onboard interactively Source: https://nx.dev/docs/reference/nx-cloud-cli Starts the interactive onboarding wizard for connecting a workspace to Nx Cloud. Authentication is required beforehand. ```shell npx nx-cloud onboard ``` -------------------------------- ### Install and Initialize a Non-Core Nx Plugin Source: https://nx.dev/docs/reference/nx-commands Installs the latest version of a non-core Nx plugin package and runs its initialization generator if available. ```bash nx add non-core-nx-plugin ``` -------------------------------- ### Show Project Configuration Source: https://nx.dev/docs/features/ci-features/sandboxing Run this command to get a broader view of the full project configuration, including targets, inputs, and outputs. ```shell nx show project ``` -------------------------------- ### Verify @nx/remix Plugin Setup Source: https://nx.dev/docs/technologies/react/remix/introduction Confirm the @nx/remix plugin is correctly installed and integrated by checking the Nx report, verifying inferred build targets, and inspecting project configurations. ```bash nx report ``` ```bash nx show projects --with-target=build ``` ```bash nx show project my-remix-app ``` -------------------------------- ### Install Nx Cloud dependency Source: https://nx.dev/docs/guides/nx-cloud/personal-access-tokens Required for projects using Nx version 19.6 or older to enable Nx Cloud functionality. ```json // package.json { "devDependencies": { "nx-cloud": "latest" } } ``` -------------------------------- ### Configure Web Server for Playwright E2E Source: https://nx.dev/docs/technologies/test-tools/playwright/introduction Automatically set up web server options in the Playwright configuration during E2E setup for an existing project. Specify the command to start the server and its address. ```bash nx g @nx/playwright:configuration --project=your-app-name --webServerCommand="npx serve your-project-name" --webServerAddress="http://localhost:4200" ``` -------------------------------- ### Example package.json Scripts Source: https://nx.dev/docs/guides/adopting-nx/adding-to-existing-project Illustrates typical scripts found in a project's `package.json` before Nx integration. ```json // package.json { ... "scripts": { "build": "next build", "lint": "eslint ./src", "test": "node ./run-tests.js" } } ``` -------------------------------- ### Build Angular Rspack application Source: https://nx.dev/docs/technologies/angular/angular-rspack/guides/getting-started Build the Angular Rspack application using Nx inferred tasks. This command handles both client and server builds automatically. ```shell npx nx build myapp ``` -------------------------------- ### Initialize Nx Workspace Source: https://nx.dev/docs/getting-started/setup-ci Use this command to add Nx to an existing repository or to start a new Nx workspace. ```shell npx nx@latest init ``` ```shell npx create-nx-workspace@latest ``` -------------------------------- ### Enable directory listing with file-server Source: https://nx.dev/docs/reference/web/executors Serve the 'myapp' project with directory listing enabled by passing the '-d' flag, which is an additional http-server option. ```bash nx serve myapp -d ``` -------------------------------- ### Jenkins Pipeline Configuration for Nx Cloud Source: https://nx.dev/docs/guides/nx-cloud/setup-ci Configure a Jenkins pipeline to utilize Nx Cloud for building and testing affected projects. This example shows setting environment variables and running npm install. ```groovy pipeline { agent none environment { NX_BRANCH = env.BRANCH_NAME.replace('PR-', '') } stages { stage('Pipeline') { parallel { stage('Main') { when { branch 'main' } agent any steps { // This line enables distribution // The "--stop-agents-after" is optional, but allows idle agents to shut down once the "e2e-ci" targets have been requested // sh "npx nx start-ci-run --distribute-on='3 linux-medium-js' --stop-agents-after='e2e-ci'" sh "npm ci" // Prepend any command with "nx record --" to record its logs to Nx Cloud // This requires connecting your workspace to Nx Cloud. Run "nx connect" to get started w/ Nx Cloud ``` -------------------------------- ### Exclude all e2e projects except one using negation Source: https://nx.dev/docs/reference/nx-json Use negation patterns starting with `!` to exclude specific projects. Later patterns override earlier ones. This example excludes all e2e projects except `toolkit-workspace-e2e`. ```jsonc // nx.json { "plugins": [ { "plugin": "@nx/jest/plugin", "exclude": ["**/*-e2e/**/*", "!**/toolkit-workspace-e2e/**/*"], }, ], } ``` -------------------------------- ### Clone Sample Repository Source: https://nx.dev/docs/getting-started/tutorials/gradle-tutorial Download the sample multi-module Gradle project from GitHub. ```shell git clone https://github.com//gradle-tutorial.git ``` -------------------------------- ### Create a new Nx Workspace with Angular Rspack Source: https://nx.dev/docs/technologies/angular/angular-rspack/guides/getting-started Use the npx create-nx-workspace command to scaffold a new monorepo configured with Angular and Rspack. This supports both client-side rendering and server-side rendering configurations. ```shell npx create-nx-workspace myorg ``` -------------------------------- ### Nx Cloud Orchestrator Configuration in GitLab CI Source: https://nx.dev/docs/guides/nx-cloud/bring-your-own-compute Set up a base GitLab CI pipeline template for running Nx DTE orchestrator jobs. Includes dependency installation and environment variable setup for base and head commits. ```yaml .base-pipeline: interruptible: true only: - main - merge_requests cache: key: files: - yarn.lock paths: - '.yarn-cache/' before_script: - yarn install --cache-folder .yarn-cache --prefer-offline --frozen-lockfile - NX_HEAD=$CI_COMMIT_SHA - NX_BASE=${CI_MERGE_REQUEST_DIFF_BASE_SHA:-$CI_COMMIT_BEFORE_SHA} artifacts: expire_in: 5 days paths: - dist ``` -------------------------------- ### Custom Cypress Component Testing Configuration Source: https://nx.dev/docs/technologies/react/next/generators This example shows how to extend the default Cypress component testing configuration by merging additional options with the `nxComponentTestingPreset`. This allows for customization beyond the standard setup. ```typescript import { defineConfig } from 'cypress'; import { nxComponentTestingPreset } from '@nx/next/plugins/component-testing'; export default defineConfig({ component: { ...nxComponentTestingPreset(__filename), // extra options here }, }); ``` -------------------------------- ### Initialize Nx Source: https://nx.dev/docs/getting-started/tutorials/gradle-tutorial Run the initialization command to add Nx to the repository and configure the Gradle plugin. ```shell nx init ``` -------------------------------- ### @nx/dotnet Configuration Example Source: https://nx.dev/docs/technologies/dotnet/introduction Configure the @nx/dotnet plugin in nx.json, including renaming targets and setting build configurations. ```json { "plugins": [ { "plugin": "@nx/dotnet", "options": { "build": { "targetName": "compile", "configurations": { "production": { "optimization": true } } }, "test": { "targetName": "unit-test", "dependsOn": ["build"] }, "pack": false } } ] } ``` -------------------------------- ### Serve Angular Rspack Application Source: https://nx.dev/docs/technologies/angular/angular-rspack/guides/getting-started Executes the Nx serve command to launch the development server for an Angular Rspack application. It supports both CSR and SSR modes with automatic Hot Module Replacement (HMR) enabled. ```shell npx nx serve myapp ``` -------------------------------- ### Nx Console Autocompletion Schema Example (JSON) Source: https://nx.dev/docs/extending-nx/local-generators This JSON schema demonstrates the usage of `x-completion-type` and `x-completion-glob` properties. `x-completion-type` specifies the type of autocompletion, and `x-completion-glob` provides a glob pattern to filter file suggestions. ```json // schema.json { "properties": { "tsConfig": { "type": "string", "x-completion-type": "file", "x-completion-glob": "tsconfig*.json" } } } ``` -------------------------------- ### Serve React Application Source: https://nx.dev/docs/technologies/react/introduction Start the development server for your React application. This enables hot module replacement for local development. ```bash nx serve my-app ``` -------------------------------- ### Add Nx and @nx/dotnet to a .NET Workspace Source: https://nx.dev/docs/technologies/dotnet/introduction Initialize Nx and add the @nx/dotnet plugin to an existing .NET workspace. ```bash nx init ``` -------------------------------- ### Setup Tailwind CSS for Vue Projects Source: https://nx.dev/docs/technologies/vue/generators Configures Tailwind CSS for a specific Vue project within an Nx workspace. It installs necessary dependencies and generates configuration files, with options to skip formatting or package.json updates. ```bash nx generate @nx/vue:setup-tailwind [options] nx generate @nx/vue:setup-tailwind [options] ``` -------------------------------- ### Example manifest file structure Source: https://nx.dev/docs/guides/nx-release/configuration-version-prefix Shows an example of a package.json file structure before and after a version bump, demonstrating how the versionPrefix logic maintains or updates dependency constraints. ```json { "name": "my-package", "version": "0.1.1", "dependencies": { "dependency-one": "~1.2.3", "dependency-two": "^2.3.4", "dependency-three": "3.0.0" } } ``` -------------------------------- ### Add Netlify Plugin to Existing Nx Project Source: https://nx.dev/docs/technologies/node/guides/node-serverless-functions-netlify Installs the `@nx/netlify` package into an existing Nx workspace. This package provides generators and executors for Netlify integration, including function setup and deployment. ```shell nx add @nx/netlify ``` -------------------------------- ### Start Next.js Production Server Source: https://nx.dev/docs/technologies/react/next/introduction Serve the production build of your Next.js application. This command depends on the 'build' task completing successfully first. ```bash nx start my-app ``` -------------------------------- ### Add Angular Rspack application to existing workspace Source: https://nx.dev/docs/technologies/angular/angular-rspack/guides/getting-started Use the Nx generator to add an Angular application with Rspack bundling to an existing workspace. The command supports optional server-side rendering via the --ssr flag. ```shell npx nx g @nx/angular:app myapp --bundler=rspack ``` ```shell npx nx g @nx/angular:app myapp --bundler=rspack --ssr ``` -------------------------------- ### Start Expo Application Source: https://nx.dev/docs/technologies/react/expo/introduction Run this command to start the development server for your Expo application. Replace `` with the actual name of your application. ```bash nx start ``` -------------------------------- ### CircleCI Configuration for Nx Cloud Agent Jobs Source: https://nx.dev/docs/guides/nx-cloud/bring-your-own-compute This CircleCI configuration defines agent jobs for Nx Cloud distributed CI. Each agent checks out code, installs dependencies, and starts an Nx agent. It also includes steps for uploading agent metrics and self-healing CI. ```yaml agent: docker: - image: cimg/node:lts-browsers parameters: ordinal: type: integer steps: - checkout - run: npm ci # Wait for instructions from Nx Cloud - run: command: npx nx start-agent no_output_timeout: 60m environment: NX_AGENT_NAME: << parameters.ordinal >> # Upload agent resource metrics (Requires Nx 22.1 or higher.) — https://nx.dev/docs/features/ci-features/resource-usage - run: command: npx nx-cloud upload-agent-metrics environment: NX_AGENT_NAME: << parameters.ordinal >> when: always # Self-Healing CI: recommend fixes for failures. Learn more: https://nx.dev/ci/features/self-healing-ci - run: command: npx nx fix-ci environment: NX_AGENT_NAME: << parameters.ordinal >> when: always workflows: ``` -------------------------------- ### Nx Target Defaults Configuration (nx.json) Source: https://nx.dev/docs/technologies/angular/guides/setup-incremental-builds-angular Example `nx.json` configuration showing `targetDefaults`. This section defines default dependencies for targets, such as ensuring `build-base` depends on its own `build-base` targets in libraries (`^build-base`) and the `build` target depends on `build-base`. ```json { "targetDefaults": { "build": { "dependsOn": ["build-base"] }, "build-base": { "dependsOn": ["^build-base"] } } } ``` -------------------------------- ### Connect to Nx Cloud for Remote Caching Source: https://nx.dev/docs/features/cache-task-results Initiate the connection to Nx Cloud to enable remote caching. This command-line interface (CLI) command guides you through the setup process for sharing build caches across different CI runs and collaborators. ```shell npx nx@latest connect ``` -------------------------------- ### Run a target for a project Source: https://nx.dev/docs/reference/nx-commands Execute the 'build' target for the 'myapp' project. This is a basic command to start a build process. ```bash nx run myapp:build ``` -------------------------------- ### Docker Version Scheme Examples Source: https://nx.dev/docs/reference/nx-json Examples of version schemes for Docker releases using placeholders like project name, date, and commit SHA. Customize date formats using YYYY, MM, DD, HH, mm, ss tokens. ```text {currentDate|YYMM.DD}.{shortCommitSha} ``` ```text {projectName}-{currentDate|YYYY.MM.DD} ``` ```text {currentDate|YY.MM.DD.HHmm}-{commitSha} ``` ```text {projectName}-{versionActionsVersion} ``` -------------------------------- ### Create Nx Workspace and Add Angular Plugin Source: https://nx.dev/docs/technologies/module-federation/concepts/faster-builds-with-module-federation This snippet shows how to create a new Nx workspace and then install the Angular plugin. This is the starting point for Angular projects that intend to use Nx's features, including Module Federation. ```shell npx create-nx-workspace acme --preset=apps cd acme nx add @nx/angular ``` -------------------------------- ### Nx Angular Library Build Configuration for Incremental Builds Source: https://nx.dev/docs/technologies/angular/guides/setup-incremental-builds-angular Example of a project configuration file for an Angular library in Nx, showcasing the use of the `@nx/angular:ng-packagr-lite` executor, which is optimized for incremental builds. It details the 'build' target, its outputs, and configurations. ```json { "projectType": "library", ... "targets": { "build": { "executor": "@nx/angular:ng-packagr-lite", "outputs": [ "{workspaceRoot}/dist/libs/my-lib" ], "options": { ... }, "configurations": { ... }, "defaultConfiguration": "production" }, ... }, ... } ``` -------------------------------- ### Specify Dependency File Patterns Source: https://nx.dev/docs/guides/tasks--caching/configure-inputs Demonstrates how to target specific file patterns from dependencies using the ^{projectRoot} syntax or the object-based fileset configuration. ```jsonc // nx.json { "targetDefaults": { "build": { "inputs": [ "production", "^{projectRoot}/src/**/*.ts" ] } } } ``` ```jsonc { "inputs": [ "production", { "fileset": "{projectRoot}/src/**/*.ts", "dependencies": true } ] } ``` -------------------------------- ### Example package.json with Nx targets Source: https://nx.dev/docs/getting-started/tutorials/reducing-configuration-boilerplate This snippet shows how to define build and test tasks within a project's `package.json` using Nx's `nx.json` configuration. It includes settings for caching, dependencies, inputs, and outputs. ```jsonc // packages/my-lib/package.json { "scripts": { "build": "vite build", "test": "vitest run" }, "nx": { "targets": { "build": { "cache": true, "dependsOn": ["^build"], "inputs": [ "{projectRoot}/src/**/*", "{projectRoot}/vite.config.ts", "{projectRoot}/tsconfig.json" ], "outputs": ["{projectRoot}/dist"] }, "test": { "cache": true, "inputs": ["{projectRoot}/src/**/*", "{projectRoot}/vitest.config.ts"], "outputs": ["{projectRoot}/coverage"] } } } } ``` -------------------------------- ### Generate Nx Plugin with Create Package Source: https://nx.dev/docs/extending-nx/create-install-package Generates a new Nx plugin and simultaneously sets up a "create-package-name" for it, allowing for custom project bootstrapping. This command simplifies the initial setup of a plugin intended for direct project creation. ```shell npx create-nx-plugin my-plugin --create-package-name create-my-plugin ```