[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-fe098391-835f-4a9e-8707-406d0d23ed7f":3,"$fe-2g3bvnN9jctZLhbRX0ysWMcelIIyk9yM_kScpcYRA":43},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":34},"fe098391-835f-4a9e-8707-406d0d23ed7f","nx-workspace-patterns","配置和优化Nx单仓库工作空间。在设置Nx、配置项目边界、优化构建缓存或实现受影响命令时使用。","cat_life_career","mod_other","sickn33,other","---\nname: nx-workspace-patterns\ndescription: \"Configure and optimize Nx monorepo workspaces. Use when setting up Nx, configuring project boundaries, optimizing build caching, or implementing affected commands.\"\nrisk: unknown\nsource: community\ndate_added: \"2026-02-27\"\n---\n\n# Nx Workspace Patterns\n\nProduction patterns for Nx monorepo management.\n\n## Do not use this skill when\n\n- The task is unrelated to nx workspace patterns\n- You need a different domain or tool outside this scope\n\n## Instructions\n\n- Clarify goals, constraints, and required inputs.\n- Apply relevant best practices and validate outcomes.\n- Provide actionable steps and verification.\n- If detailed examples are required, open `resources\u002Fimplementation-playbook.md`.\n\n## Use this skill when\n\n- Setting up new Nx workspaces\n- Configuring project boundaries\n- Optimizing CI with affected commands\n- Implementing remote caching\n- Managing dependencies between projects\n- Migrating to Nx\n\n## Core Concepts\n\n### 1. Nx Architecture\n\n```\nworkspace\u002F\n├── apps\u002F              # Deployable applications\n│   ├── web\u002F\n│   └── api\u002F\n├── libs\u002F              # Shared libraries\n│   ├── shared\u002F\n│   │   ├── ui\u002F\n│   │   └── utils\u002F\n│   └── feature\u002F\n│       ├── auth\u002F\n│       └── dashboard\u002F\n├── tools\u002F             # Custom executors\u002Fgenerators\n├── nx.json            # Nx configuration\n└── workspace.json     # Project configuration\n```\n\n### 2. Library Types\n\n| Type | Purpose | Example |\n|------|---------|---------|\n| **feature** | Smart components, business logic | `feature-auth` |\n| **ui** | Presentational components | `ui-buttons` |\n| **data-access** | API calls, state management | `data-access-users` |\n| **util** | Pure functions, helpers | `util-formatting` |\n| **shell** | App bootstrapping | `shell-web` |\n\n## Templates\n\n### Template 1: nx.json Configuration\n\n```json\n{\n  \"$schema\": \".\u002Fnode_modules\u002Fnx\u002Fschemas\u002Fnx-schema.json\",\n  \"npmScope\": \"myorg\",\n  \"affected\": {\n    \"defaultBase\": \"main\"\n  },\n  \"tasksRunnerOptions\": {\n    \"default\": {\n      \"runner\": \"nx\u002Ftasks-runners\u002Fdefault\",\n      \"options\": {\n        \"cacheableOperations\": [\n          \"build\",\n          \"lint\",\n          \"test\",\n          \"e2e\",\n          \"build-storybook\"\n        ],\n        \"parallel\": 3\n      }\n    }\n  },\n  \"targetDefaults\": {\n    \"build\": {\n      \"dependsOn\": [\"^build\"],\n      \"inputs\": [\"production\", \"^production\"],\n      \"cache\": true\n    },\n    \"test\": {\n      \"inputs\": [\"default\", \"^production\", \"{workspaceRoot}\u002Fjest.preset.js\"],\n      \"cache\": true\n    },\n    \"lint\": {\n      \"inputs\": [\"default\", \"{workspaceRoot}\u002F.eslintrc.json\"],\n      \"cache\": true\n    },\n    \"e2e\": {\n      \"inputs\": [\"default\", \"^production\"],\n      \"cache\": true\n    }\n  },\n  \"namedInputs\": {\n    \"default\": [\"{projectRoot}\u002F**\u002F*\", \"sharedGlobals\"],\n    \"production\": [\n      \"default\",\n      \"!{projectRoot}\u002F**\u002F?(*.)+(spec|test).[jt]s?(x)?(.snap)\",\n      \"!{projectRoot}\u002Ftsconfig.spec.json\",\n      \"!{projectRoot}\u002Fjest.config.[jt]s\",\n      \"!{projectRoot}\u002F.eslintrc.json\"\n    ],\n    \"sharedGlobals\": [\n      \"{workspaceRoot}\u002Fbabel.config.json\",\n      \"{workspaceRoot}\u002Ftsconfig.base.json\"\n    ]\n  },\n  \"generators\": {\n    \"@nx\u002Freact\": {\n      \"application\": {\n        \"style\": \"css\",\n        \"linter\": \"eslint\",\n        \"bundler\": \"webpack\"\n      },\n      \"library\": {\n        \"style\": \"css\",\n        \"linter\": \"eslint\"\n      },\n      \"component\": {\n        \"style\": \"css\"\n      }\n    }\n  }\n}\n```\n\n### Template 2: Project Configuration\n\n```json\n\u002F\u002F apps\u002Fweb\u002Fproject.json\n{\n  \"name\": \"web\",\n  \"$schema\": \"..\u002F..\u002Fnode_modules\u002Fnx\u002Fschemas\u002Fproject-schema.json\",\n  \"sourceRoot\": \"apps\u002Fweb\u002Fsrc\",\n  \"projectType\": \"application\",\n  \"tags\": [\"type:app\", \"scope:web\"],\n  \"targets\": {\n    \"build\": {\n      \"executor\": \"@nx\u002Fwebpack:webpack\",\n      \"outputs\": [\"{options.outputPath}\"],\n      \"defaultConfiguration\": \"production\",\n      \"options\": {\n        \"compiler\": \"babel\",\n        \"outputPath\": \"dist\u002Fapps\u002Fweb\",\n        \"index\": \"apps\u002Fweb\u002Fsrc\u002Findex.html\",\n        \"main\": \"apps\u002Fweb\u002Fsrc\u002Fmain.tsx\",\n        \"tsConfig\": \"apps\u002Fweb\u002Ftsconfig.app.json\",\n        \"assets\": [\"apps\u002Fweb\u002Fsrc\u002Fassets\"],\n        \"styles\": [\"apps\u002Fweb\u002Fsrc\u002Fstyles.css\"]\n      },\n      \"configurations\": {\n        \"development\": {\n          \"extractLicenses\": false,\n          \"optimization\": false,\n          \"sourceMap\": true\n        },\n        \"production\": {\n          \"optimization\": true,\n          \"outputHashing\": \"all\",\n          \"sourceMap\": false,\n          \"extractLicenses\": true\n        }\n      }\n    },\n    \"serve\": {\n      \"executor\": \"@nx\u002Fwebpack:dev-server\",\n      \"defaultConfiguration\": \"development\",\n      \"options\": {\n        \"buildTarget\": \"web:build\"\n      },\n      \"configurations\": {\n        \"development\": {\n          \"buildTarget\": \"web:build:development\"\n        },\n        \"production\": {\n          \"buildTarget\": \"web:build:production\"\n        }\n      }\n    },\n    \"test\": {\n      \"executor\": \"@nx\u002Fjest:jest\",\n      \"outputs\": [\"{workspaceRoot}\u002Fcoverage\u002F{projectRoot}\"],\n      \"options\": {\n        \"jestConfig\": \"apps\u002Fweb\u002Fjest.config.ts\",\n        \"passWithNoTests\": true\n      }\n    },\n    \"lint\": {\n      \"executor\": \"@nx\u002Feslint:lint\",\n      \"outputs\": [\"{options.outputFile}\"],\n      \"options\": {\n        \"lintFilePatterns\": [\"apps\u002Fweb\u002F**\u002F*.{ts,tsx,js,jsx}\"]\n      }\n    }\n  }\n}\n```\n\n### Template 3: Module Boundary Rules\n\n```json\n\u002F\u002F .eslintrc.json\n{\n  \"root\": true,\n  \"ignorePatterns\": [\"**\u002F*\"],\n  \"plugins\": [\"@nx\"],\n  \"overrides\": [\n    {\n      \"files\": [\"*.ts\", \"*.tsx\", \"*.js\", \"*.jsx\"],\n      \"rules\": {\n        \"@nx\u002Fenforce-module-boundaries\": [\n          \"error\",\n          {\n            \"enforceBuildableLibDependency\": true,\n            \"allow\": [],\n            \"depConstraints\": [\n              {\n                \"sourceTag\": \"type:app\",\n                \"onlyDependOnLibsWithTags\": [\n                  \"type:feature\",\n                  \"type:ui\",\n                  \"type:data-access\",\n                  \"type:util\"\n                ]\n              },\n              {\n                \"sourceTag\": \"type:feature\",\n                \"onlyDependOnLibsWithTags\": [\n                  \"type:ui\",\n                  \"type:data-access\",\n                  \"type:util\"\n                ]\n              },\n              {\n                \"sourceTag\": \"type:ui\",\n                \"onlyDependOnLibsWithTags\": [\"type:ui\", \"type:util\"]\n              },\n              {\n                \"sourceTag\": \"type:data-access\",\n                \"onlyDependOnLibsWithTags\": [\"type:data-access\", \"type:util\"]\n              },\n              {\n                \"sourceTag\": \"type:util\",\n                \"onlyDependOnLibsWithTags\": [\"type:util\"]\n              },\n              {\n                \"sourceTag\": \"scope:web\",\n                \"onlyDependOnLibsWithTags\": [\"scope:web\", \"scope:shared\"]\n              },\n              {\n                \"sourceTag\": \"scope:api\",\n                \"onlyDependOnLibsWithTags\": [\"scope:api\", \"scope:shared\"]\n              },\n              {\n                \"sourceTag\": \"scope:shared\",\n                \"onlyDependOnLibsWithTags\": [\"scope:shared\"]\n              }\n            ]\n          }\n        ]\n      }\n    }\n  ]\n}\n```\n\n### Template 4: Custom Generator\n\n```typescript\n\u002F\u002F tools\u002Fgenerators\u002Ffeature-lib\u002Findex.ts\nimport {\n  Tree,\n  formatFiles,\n  generateFiles,\n  joinPathFragments,\n  names,\n  readProjectConfiguration,\n} from '@nx\u002Fdevkit';\nimport { libraryGenerator } from '@nx\u002Freact';\n\ninterface FeatureLibraryGeneratorSchema {\n  name: string;\n  scope: string;\n  directory?: string;\n}\n\nexport default async function featureLibraryGenerator(\n  tree: Tree,\n  options: FeatureLibraryGeneratorSchema\n) {\n  const { name, scope, directory } = options;\n  const projectDirectory = directory\n    ? `${directory}\u002F${name}`\n    : `libs\u002F${scope}\u002Ffeature-${name}`;\n\n  \u002F\u002F Generate base library\n  await libraryGenerator(tree, {\n    name: `feature-${name}`,\n    directory: projectDirectory,\n    tags: `type:feature,scope:${scope}`,\n    style: 'css',\n    skipTsConfig: false,\n    skipFormat: true,\n    unitTestRunner: 'jest',\n    linter: 'eslint',\n  });\n\n  \u002F\u002F Add custom files\n  const projectConfig = readProjectConfiguration(tree, `${scope}-feature-${name}`);\n  const projectNames = names(name);\n\n  generateFiles(\n    tree,\n    joinPathFragments(__dirname, 'files'),\n    projectConfig.sourceRoot,\n    {\n      ...projectNames,\n      scope,\n      tmpl: '',\n    }\n  );\n\n  await formatFiles(tree);\n}\n```\n\n### Template 5: CI Configuration with Affected\n\n```yaml\n# .github\u002Fworkflows\u002Fci.yml\nname: CI\n\non:\n  push:\n    branches: [main]\n  pull_request:\n    branches: [main]\n\nenv:\n  NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}\n\njobs:\n  main:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions\u002Fcheckout@v4\n        with:\n          fetch-depth: 0\n\n      - uses: actions\u002Fsetup-node@v4\n        with:\n          node-version: 20\n          cache: 'npm'\n\n      - name: Install dependencies\n        run: npm ci\n\n      - name: Derive SHAs for affected commands\n        uses: nrwl\u002Fnx-set-shas@v4\n\n      - name: Run affected lint\n        run: npx nx affected -t lint --parallel=3\n\n      - name: Run affected test\n        run: npx nx affected -t test --parallel=3 --configuration=ci\n\n      - name: Run affected build\n        run: npx nx affected -t build --parallel=3\n\n      - name: Run affected e2e\n        run: npx nx affected -t e2e --parallel=1\n```\n\n### Template 6: Remote Caching Setup\n\n```typescript\n\u002F\u002F nx.json with Nx Cloud\n{\n  \"tasksRunnerOptions\": {\n    \"default\": {\n      \"runner\": \"nx-cloud\",\n      \"options\": {\n        \"cacheableOperations\": [\"build\", \"lint\", \"test\", \"e2e\"],\n        \"accessToken\": \"your-nx-cloud-token\",\n        \"parallel\": 3,\n        \"cacheDirectory\": \".nx\u002Fcache\"\n      }\n    }\n  },\n  \"nxCloudAccessToken\": \"your-nx-cloud-token\"\n}\n\n\u002F\u002F Self-hosted cache with S3\n{\n  \"tasksRunnerOptions\": {\n    \"default\": {\n      \"runner\": \"@nx-aws-cache\u002Fnx-aws-cache\",\n      \"options\": {\n        \"cacheableOperations\": [\"build\", \"lint\", \"test\"],\n        \"awsRegion\": \"us-east-1\",\n        \"awsBucket\": \"my-nx-cache-bucket\",\n        \"awsProfile\": \"default\"\n      }\n    }\n  }\n}\n```\n\n## Common Commands\n\n```bash\n# Generate new library\nnx g @nx\u002Freact:lib feature-auth --directory=libs\u002Fweb --tags=type:feature,scope:web\n\n# Run affected tests\nnx affected -t test --base=main\n\n# View dependency graph\nnx graph\n\n# Run specific project\nnx build web --configuration=production\n\n# Reset cache\nnx reset\n\n# Run migrations\nnx migrate latest\nnx migrate --run-migrations\n```\n\n## Best Practices\n\n### Do's\n- **Use tags consistently** - Enforce with module boundaries\n- **Enable caching early** - Significant CI savings\n- **Keep libs focused** - Single responsibility\n- **Use generators** - Ensure consistency\n- **Document boundaries** - Help new developers\n\n### Don'ts\n- **Don't create circular deps** - Graph should be acyclic\n- **Don't skip affected** - Test only what changed\n- **Don't ignore boundaries** - Tech debt accumulates\n- **Don't over-granularize** - Balance lib count\n\n## Resources\n\n- [Nx Documentation](https:\u002F\u002Fnx.dev\u002Fgetting-started\u002Fintro)\n- [Module Boundaries](https:\u002F\u002Fnx.dev\u002Fcore-features\u002Fenforce-module-boundaries)\n- [Nx Cloud](https:\u002F\u002Fnx.app\u002F)\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,172,1604,"2026-05-16 13:31:18",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"其他","other","mdi-page-next-outline","其他类型Skill",5,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":32,"skillCount":33,"createdAt":26},"职场发展","career","mdi-briefcase-outline","面试准备、简历优化、职业规划",4,575,[35],{"id":36,"skillId":4,"version":37,"fileName":38,"fileSize":39,"filePath":40,"fileHash":41,"manifest":42,"createdAt":19},"2dd5765e-e1e5-4754-82c4-e321116a3c59","1.0.0","nx-workspace-patterns.zip",3846,"uploads\u002Fskills\u002Ffe098391-835f-4a9e-8707-406d0d23ed7f\u002Fnx-workspace-patterns.zip","bb83d1829bb5cba7ee297f92bb0a47be6977d750b74bfe0ce1ec2d44f94d8acc","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":11581}]",{"code":44,"message":45,"data":46},200,"success",{"items":47,"stats":48,"page":51},[],{"averageRating":49,"totalRatings":49,"ratingCounts":50},0,[49,49,49,49,49],{"limit":52,"offset":49,"hasMore":53,"nextOffset":52,"ratedOnly":16},15,false]