nx-run-tasks
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseYou can run tasks with Nx in the following way.
Keep in mind that you might have to prefix things with npx/pnpx/yarn if the user doesn't have nx installed globally. Look at the package.json or lockfile to determine which package manager is in use.
For more details on any command, run it with (e.g. , ).
--helpnx run-many --helpnx affected --help你可以通过以下方式使用Nx运行任务。
请注意,如果用户没有全局安装nx,可能需要在命令前加上npx/pnpx/yarn前缀。查看package.json或锁定文件来确定使用的包管理器。
如需了解任何命令的更多细节,可在命令后添加参数运行(例如、)。
--helpnx run-many --helpnx affected --helpUnderstand which tasks can be run
了解可运行的任务
You can check those via , for example . It contains a section which has information about targets that can be run. You can also just look at the scripts or targets, but you might miss out on inferred tasks by Nx plugins.
nx show project <projectname> --jsonnx show project myapp --jsontargetspackage.jsonproject.json你可以通过命令查看可运行的任务,例如。该命令的输出包含一个部分,其中列出了可运行的目标任务信息。你也可以直接查看中的scripts或中的targets,但这样可能会遗漏Nx插件自动推断出的任务。
nx show project <projectname> --jsonnx show project myapp --jsontargetspackage.jsonproject.jsonRun a single task
运行单个任务
nx run <project>:<task>where is the project name defined in or (if present).
projectpackage.jsonproject.jsonnx run <project>:<task>其中是或(如果存在)中定义的项目名称。
projectpackage.jsonproject.jsonRun multiple tasks
运行多个任务
nx run-many -t build test lint typecheckYou can pass a flag to filter to specific projects, otherwise it runs on all projects. You can also use to exclude projects, and to control the number of parallel processes (default is 3).
-p--exclude--parallelExamples:
- — test specific projects
nx run-many -t test -p proj1 proj2 - — test projects matching a pattern
nx run-many -t test --projects=*-app --exclude=excluded-app - — test projects by tag
nx run-many -t test --projects=tag:api-*
nx run-many -t build test lint typecheck你可以使用标志筛选特定项目,否则会在所有项目上运行任务。你还可以使用排除项目,以及控制并行进程的数量(默认是3个)。
-p--exclude--parallel示例:
- — 测试特定项目
nx run-many -t test -p proj1 proj2 - — 测试匹配指定模式的项目
nx run-many -t test --projects=*-app --exclude=excluded-app - — 按标签测试项目
nx run-many -t test --projects=tag:api-*
Run tasks for affected projects
为受影响的项目运行任务
Use to only run tasks on projects that have been changed and projects that depend on changed projects. This is especially useful in CI and for large workspaces.
nx affectednx affected -t build test lintBy default it compares against the base branch. You can customize this:
- — compare against a specific base and head
nx affected -t test --base=main --head=HEAD - — specify changed files directly
nx affected -t test --files=libs/mylib/src/index.ts
使用仅在已更改的项目及其依赖项目上运行任务。这在CI环境和大型工作区中尤其有用。
nx affectednx affected -t build test lint默认情况下,它会与基准分支进行比较。你可以自定义该行为:
- — 与指定的基准分支和当前分支进行比较
nx affected -t test --base=main --head=HEAD - — 直接指定已更改的文件
nx affected -t test --files=libs/mylib/src/index.ts
Useful flags
实用标志
These flags work with , , and :
runrun-manyaffected- — rerun tasks even when results are cached
--skipNxCache - — print additional information such as stack traces
--verbose - — stop execution after the first failed task
--nxBail - — use a specific configuration (e.g.
--configuration=<name>)production
以下标志适用于、和命令:
runrun-manyaffected- — 即使结果已缓存,也重新运行任务
--skipNxCache - — 打印额外信息,如堆栈跟踪
--verbose - — 第一个任务失败后立即停止执行
--nxBail - — 使用特定配置(例如
--configuration=<name>)production