重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
npx skills add https://github.com/nrwl/nx --skill nx-generateNx 生成器是强大的工具,可用于在 monorepo 中搭建项目、进行自动化代码迁移或自动化重复性任务。它们确保整个代码库的一致性并减少样板工作。
当用户想要执行以下操作时,此技能适用:
使用 Nx CLI 来发现可用的生成器:
npx nx list @nx/reactnpx nx list这包括:
@nx/react:library、@nx/js:library)根据用户的请求,确定哪个(些)生成器可以满足他们的需求。考虑:
重要提示:当本地工作区生成器和外部插件生成器都可以满足请求时,。本地生成器是针对特定仓库的模式和约定定制的。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
用户请求的内容可能没有任何 Nx 生成器支持。在这种情况下,您可以停止使用此技能,并尝试以其他方式帮助用户。但是,证明这一点的门槛很高。在放弃之前,请仔细考虑每一个可用的生成器。在做出决定之前,详细查看任何可能相关的生成器。
在运行任何生成器之前,请完成以下步骤:
使用 --help 标志来了解所有可用选项:
npx nx g @nx/react:library --help
注意:
了解生成器实际执行的操作有助于您:
查找生成器源代码:
node -e "console.log(require.resolve('@nx/<plugin>/generators.json'));" 找到 generators.json,然后从那里定位源代码node_modules/<plugin>/generators.json 读取tools/generators/ 或本地插件目录中。您可以在仓库中搜索生成器名称来找到它。一旦您对所选生成器的功能有了了解,请重新考虑:这是否是满足用户请求的正确生成器?如果不是,可以返回生成器发现流程,并在继续之前选择不同的生成器。如果这样做,请确保再次完成整个执行前检查清单。
在生成之前,检查代码库的目标区域:
例如,如果类似的库正在使用特定的测试运行器、构建工具或 linter,请尽可能匹配。如果项目或其他工件按照特定的命名约定组织,请尝试匹配它。
确保所有必需选项都有值:
请注意,如果用户没有全局安装 nx,您可能需要在命令前加上 npx/pnpx/yarn。许多生成器会根据执行位置的不同而有不同的行为。例如,第一方 nx 库生成器使用当前工作目录来确定库应放置的目录。这一点非常重要。
强烈建议先使用 --dry-run 运行,但不是强制性的。请自行判断:
--dry-run 可能会失败。不要气馁,只需继续实际运行生成器,并从那里开始迭代。执行生成器:
nx generate <generator-name> <options> --no-interactive
关键:始终包含 --no-interactive 以防止出现导致执行挂起的提示。
示例:
nx generate @nx/react:library --name=my-utils --no-interactive
如果生成器失败:
常见的失败原因:
生成器提供了一个起点,但输出可能需要调整以满足用户的具体要求:
对所有生成/修改的文件运行格式化:
nx format --fix
JavaScript/TypeScript 以外的语言可能也需要其他格式化调用。
验证生成的代码是否正确工作。具体操作将根据生成器类型和可用目标而有所不同。如果生成器创建了一个新项目,直接运行其目标。请运用最佳判断来确定需要验证的内容。
示例:
nx lint <new-project>
nx test <new-project>
nx build <new-project>
当验证失败时:
如果范围可控(少量 lint 错误、次要类型问题):
如果问题广泛(许多错误、复杂问题):
--no-interactive 以防止挂起每周安装数
70
仓库
GitHub 星标数
28.4K
首次出现
2026年1月30日
安全审计
已安装于
opencode66
github-copilot61
codex61
gemini-cli61
cursor59
amp58
Nx generators are powerful tools that scaffold projects, make automated code migrations or automate repetitive tasks in a monorepo. They ensure consistency across the codebase and reduce boilerplate work.
This skill applies when the user wants to:
Use the Nx CLI to discover available generators:
npx nx list @nx/reactnpx nx listThis includes:
@nx/react:library, @nx/js:library)Based on the user's request, identify which generator(s) could fulfill their needs. Consider:
IMPORTANT : When both a local workspace generator and an external plugin generator could satisfy the request, always prefer the local workspace generator. Local generators are customized for the specific repo's patterns and conventions.
It's possible that the user request is something that no Nx generator exists for whatsoever. In this case, you can stop using this skill and try to help the user another way. HOWEVER, the burden of proof for this is high. Before aborting, carefully consider each and every generator that's available. Look into details for any that could be related in any way before making this decision.
Before running any generator, complete these steps:
Use the --help flag to understand all available options:
npx nx g @nx/react:library --help
Pay attention to:
Understanding what the generator actually does helps you:
To find generator source code:
node -e "console.log(require.resolve('@nx/<plugin>/generators.json'));" to find the generators.json, then locate the source from therenode_modules/<plugin>/generators.jsontools/generators/ or a local plugin directory. You can search the repo for the generator name to find it.Once you have built up an understanding of what the selected generator does, reconsider: Is this the right generator to service the user request? If not, it's okay to go back to the Generator Discovery Flow and select a different generator before proceeding. If you do, make sure to go through the entire pre-execution checklist once more.
Before generating, examine the target area of the codebase:
For example, if similar libraries are using a specific test runner, build tool or linter, try to match that if possible. If projects or other artifacts are organized with a specific naming convention, try to match it.
Ensure all required options have values:
Keep in mind that you might have to prefix things with npx/pnpx/yarn if the user doesn't have nx installed globally. Many generators will behave differently based on where they are executed. For example, first-party nx library generators use the cwd to determine the directory that the library should be placed in. This is highly important.
Running with --dry-run first is strongly encouraged but not mandatory. Use your judgment:
Execute the generator with:
nx generate <generator-name> <options> --no-interactive
CRITICAL : Always include --no-interactive to prevent prompts that would hang the execution.
Example:
nx generate @nx/react:library --name=my-utils --no-interactive
If the generator fails:
Common failure reasons:
Generators provide a starting point, but the output may need adjustment to match the user's specific requirements:
Run formatting on all generated/modified files:
nx format --fix
Languages other than javascript/typescript might need other formatting invocations too.
Verify that the generated code works correctly. What this looks like will vary depending on the type of generator and the targets available. If the generator created a new project, run its targets directly Use your best judgement to determine what needs to be verified.
Example:
nx lint <new-project>
nx test <new-project>
nx build <new-project>
When verification fails:
If scope is manageable (a few lint errors, minor type issues):
If issues are extensive (many errors, complex problems):
Local generators first - Always prefer workspace/local generators over external plugin generators when both could work
Understand before running - Read both the schema AND the source code to fully understand what will happen
No prompts - Always use --no-interactive to prevent hanging
Generators are starting points - Modify the output as needed to fully satisfy the user's requirements
Verify changes work - Don't just generate; ensure the code builds, lints, and tests pass
Be proactive about fixes - Don't just report errors; attempt to resolve them automatically when possible
Match repo patterns - Study existing similar code in the repo and match its conventions
Weekly Installs
70
Repository
GitHub Stars
28.4K
First Seen
Jan 30, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode66
github-copilot61
codex61
gemini-cli61
cursor59
amp58
通过 LiteLLM 代理让 Claude Code 对接 GitHub Copilot 运行 | 高级变通方案指南
48,700 周安装
OpenClaw 指挥中心 - AI 工作团队任务控制面板,实时监控会话与系统状态
75 周安装
OpenZeppelin Stylus 合约设置指南:Rust 智能合约开发与部署教程
74 周安装
Notion自动化指南:通过Rube MCP与Composio实现页面、数据库与内容管理
72 周安装
Vercel自动化部署与监控指南 - 通过Rube MCP实现项目自动化管理
71 周安装
技术债务可视化工具 - 识别高息技术债务,优化代码重构优先级
78 周安装
Salesforce B2C Commerce 元数据开发指南:自定义属性、对象与站点偏好设置
71 周安装