Skip to content

giuseppe-trisciuoglio/developer-kit / plugins/developer-kit-typescript/skills/nx-monorepo

nx-monorepo

Verified

Provides comprehensive Nx monorepo management guidance for TypeScript/JavaScript projects. Use when creating Nx workspaces, generating apps/libraries/components, running affected commands, setting up CI/CD, configuring Module Federation, or implementing NestJS backends within Nx

FileKindSize
SKILL.mdskill md8.9 KB
references/advanced.mdmarkdown7.4 KB
references/basics.mdmarkdown3.9 KB
references/ci-cd.mdmarkdown7.8 KB
references/generators.mdmarkdown5.2 KB
references/nestjs.mdmarkdown7.1 KB
references/react.mdmarkdown6.3 KB
references/typescript.mdmarkdown6.8 KB

references/advanced.md

View on GitHub
# Advanced Nx Reference

## Task Orchestration

### Dependencies

Define task dependencies in `project.json`:

```json
{
  "targets": {
    "build": {
      "dependsOn": [
        { "projects": ["shared-ui"], "target": "build" },
        { "projects": ["api"], "target": "build", "params": "ignore" }
      ]
    }
  }
}
```

### Target Defaults

Configure default behavior in `nx.json`:

```json
{
  "targetDefaults": {
    "build": {
      "cache": true,
      "dependsOn": ["^build"],
      "inputs": ["production", "^production"]
    },
    "test": {
      "cache": true,
      "inputs": ["default", "^production"]
    },
    "lint": {
      "cache": true
    }
  }
}
```

## Caching

### Local Cache

Enabled by default. Cache location:

```
.nx/cache
```

### Bypass Cache

```bash
# Single run
nx run my-app:build --skip-nx-cache

# Reset cache
nx reset
```

### Remote Cache

```bash
# Install Azure cache
nx add @nx/azure-cache

# Generates activation key saved to .nx/key/key.ini
# Set as environment variable: NX_KEY
```

Configuration in `nx.json`:

```json
{
  "nxCloudId": "your-workspace-id",
  "nxCloudUrl": "https://cloud.nx.app"
}
```

## Affected Commands

### Base Configuration

```yaml
# GitHub Actions
- uses: nrwl/nx-set-shas@v4
  with:
    main-branch-name: 'main'
```

### Affected Patterns

```bash
# Basic affected
nx affected -t build

# With base/head
nx affected -t build --base=origin/main~1 --head=HEAD

# With files
nx affected -t build --files=libs/shared/*

# Exclude projects
nx affected -t build --exclude=legacy-app

# Run multiple targets
nx affected -t lint test build

# Parallel execution
nx affected -t build --parallel=5
```

## Project Graph

### Visualize Graph

```bash
# Open in browser
nx graph

# Output as JSON
nx graph --json=output.json

# Output as static HTML
nx graph --file=graph.html

# Watch mode
nx graph --watch
```

### Query Projects

```bash
# List all projects
nx show projects

# List projects with specific tags
nx show projects --tags=type:ui

# Show project details
nx show project my-app

# Show dependencies (JSON)
nx show project my-app --json

# Show affected projects
nx show projects --affected
```

## Module Federation

### Micro-Frontends Architecture

```
host-app (Shell)
├── remote1 (Checkout)
├── remote2 (Catalog)
└── remote3 (User Profile)
```

### Setup Host

```bash
nx g @nx/react:host shell-app
```

### Setup Remote

```bash
nx g @nx/react:remote checkout --name=remote1 --port=4201
```

### Add Remote to Host

```bash
nx g @nx/react:remote-configuration shell-app \
  --remote=remote1 \
  --port=4201 \
  --type=module
```

### Module Federation Config

```typescript
// apps/shell-app/module-federation.config.ts
module.exports = {
  name: 'shell',
  remotes: {
    remote1: 'remote1@http://localhost:4201/remoteEntry.js',
  },
};
```

## Named Inputs

### Configuration in nx.json

```json
{
  "namedInputs": {
    "default": ["{projectRoot}/**/*"],
    "production": [
      "default",
      "!{projectRoot}/**/*.spec.ts",
      "!{projectRoot}/**/*.test.ts",
      "!{projectRoot}/**/*.stories.ts"
    ],
    "nonProduction": [
      "default",
      "{projectRoot}/**/*.spec.ts",
      "{projectRoot}/**/*.test.ts"
    ]
  },
  "targetDefaults": {
    "build": {
      "inputs": ["production", "^production"]
    },
    "test": {
      "inputs": ["default", "^production"]
    }
  }
}
```

## Workspace Layout

### Integrated Layout

```
my-workspace/
├── apps/
├── libs/
└── tools/
```

### Standalone Projects

```
my-workspace/
├── packages/
│   ├── app1/
│   └── lib1/
```

Set in `nx.json`:

```json
{
  "workspaceLayout": {
    "appsDir": "packages",
    "libsDir": "packages"
  }
}
```

## Plugins

### Use Plugins

```json
// nx.json
{
  "plugins": [
    {
      "plugin": "@nx/react"
    },
    {
      "plugin": "@nx/js",
      "options": {
        "buildTargetName": "build",
        "testTargetName": "test"
      }
    }
  ]
}
```

### Custom Plugin Options

```json
{
  "plugins": [
    {
      "plugin": "@nx/dotnet",
      "options": {
        "build": {
          "targetName": "compile",
          "configurations": {
            "production": { "optimization": true }
          }
        },
        "test": {
          "targetName": "unit-test",
          "dependsOn": ["build"]
        }
      }
    }
  ]
}
```

## Generators

### Custom Workspace Generator

```bash
# Create generator
nx g workspace-generator my-generator

# Run generator
nx workspace-generator my-generator
```

### Sync Generator

Run automatically after `npm install` / `yarn`:

```bash
nx g @nx/js:lib my-lib --sync
```

## Release

### Version Projects

```bash
# Version all
nx release version --version=1.0.0

# Version specific projects
nx release version --projects=my-lib --version=1.2.3

# Interactive
nx release version
```

### Publish

```bash
# Dry run
nx release publish --dry-run

# Publish
nx release publish

# With first release
nx release publish --firstRelease
```

### Changelog

```bash
# Generate changelog
nx release changelog

# For specific version
nx release changelog --version=1.0.0
```

## Conformance

### Install Conformance

```bash
nx add @nx/conformance
```

### Configuration

```json
// nx.json
{
  "conformance": {
    "rules": [
      {
        "rule": "@nx/conformance/enforce-project-boundaries",
        "options": {},
        "projects": ["*"]
      }
    ]
  }
}
```

## Owners

### GitHub CODEOWNERS

```json
// nx.json
{
  "owners": {
    "format": "github",
    "outputPath": "CODEOWNERS",
    "patterns": [
      {
        "description": "Frontend team owns UI projects",
        "projects": ["tag:type:ui"],
        "owners": ["@frontend-team"]
      },
      {
        "description": "Backend team owns API",
        "projects": ["api"],
        "owners": ["@backend-team"]
      },
      {
        "description": "DevOps owns workflows",
        "files": [".github/workflows/**/*"],
        "owners": ["@devops"]
      }
    ]
  }
}
```

## Performance

### Task Runner Options

```json
// nx.json
{
  "targetDefaults": {
    "build": {
      "parallel": true,
      "maxParallel": 4
    }
  }
}
```

### Cache Encryption

```json
// nx.json
{
  "encryptionKey": "your-encryption-key"
}
```

## Agent Configuration (Nx Cloud)

### Launch Templates

```yaml
// .nx/workflows/agents.yaml
launch-templates:
  my-linux-medium-js:
    resource-class: 'docker_linux_amd64/medium'
    image: 'ubuntu22.04-node20.11-v9'
    init-steps:
      - name: Checkout
        uses: 'nrwl/nx-cloud-workflows/v5/workflow-steps/checkout/main.yaml'
      - name: Install Node Modules
        uses: 'nrwl/nx-cloud-workflows/v5/workflow-steps/install-node-modules/main.yaml'
```

### Start CI Run

```bash
# Manual distribution
npx nx-cloud start-ci-run --distribute-on="manual"

# Static distribution
npx nx-cloud start-ci-run --distribute-on="3 linux-medium-js"

# Stop agents after specific tasks
npx nx-cloud start-ci-run --stop-agents-after="e2e-ci"
```

## Troubleshooting

### Debug Task Execution

```bash
# Dry run
nx affected -t build --dry-run

# Verbose output
nx run my-app:build --verbose

# Show task graph
nx affected -t build --graph=stdout

# Skip cache
nx run my-app:build --skip-nx-cache
```

### Common Issues

**"Project X not found"**
- Check project name in `project.json` or `workspace.json`

**"Circular dependency detected"**
- Check `dependsOn` configuration
- Use `nx graph` to visualize dependencies

**Cache not working**
- Check `outputs` paths in `project.json`
- Verify cache directory permissions
writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deploymentStars: 322kUpdated Claude CodeCodexVerifiedInstall
xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release.Stars: 118kUpdated Claude CodeCodexVerifiedInstall