[英]Passing targets in as a dependency and making sure they output something useful and meaningful to be consumed by next target
I am trying to get a plugin to use run-commands
and I want it to run and execute a dependent task and pass the result to my command.我正在尝试让一个插件使用run-commands
,我希望它运行并执行一个依赖任务并将结果传递给我的命令。 In this case, I want to have a dependent target start up a webserver and keep it running.在这种情况下,我想让一个依赖目标启动一个网络服务器并保持它运行。
I have tried to do the following and nx graph
shows the right DAG but I am not seeing the output I want.我尝试执行以下操作, nx graph
显示了正确的 DAG,但我没有看到我想要的 output。
"executor": "nx:run-commands",
"options": {
"command": "./my-cli-tool --arg={frontendApp:serve}"
},
"dependsOn": [
"frontendApp:serve"
]
I know that in a monorepo tool like bazel, passing around the target like //frontendApp:serve
would do what I am expecting here so I am guessing there should be a way to do this in nx
.我知道在像 bazel 这样的 monorepo 工具中,像//frontendApp:serve
这样绕过目标会做我在这里期望的事情,所以我猜应该有一种方法可以在nx
中做到这一点。
Update: To help with debugging.更新:帮助调试。
If the dependency is running, it is failing silently.如果依赖项正在运行,它会静默失败。 I can run it individually, eg npx nx run frontendApp:serve
.我可以单独运行它,例如npx nx run frontendApp:serve
。 I can't see the port starting up and being taken so if something is happening, its happening silently.我看不到端口正在启动和被占用,所以如果有什么事情发生,它会悄无声息地发生。
dependsOn
configuration looks a little different. dependsOn
配置看起来有点不同。 It's in the docs here:它在此处的文档中:
https://nx.dev/reference/project-configuration#dependson https://nx.dev/reference/project-configuration#dependson
Basically, you need have a local target which invokes the target in the other project.基本上,您需要有一个本地目标来调用其他项目中的目标。
{
"foo": {
"executor": "nx:run-commands",
"options": {
"command": "./my-cli-tool --arg={frontendApp:serve}"
},
"dependsOn": ["serve"]
},
"serve": {
"executor": "nx:run-commands",
"options": {
"command": "nx run frontendApp:serve"
}
}
}
Another option is to use Angular DevKit's allOf
or concat
executors for running multiple things at once:另一种选择是使用 Angular DevKit 的allOf
或concat
执行器一次运行多个东西:
"serve-with-graphql": {
"executor": "@angular-devkit/architect:allOf",
"options": {
"targets": [
{
"target": "web:serve"
},
{
"target": "graphql:dev-server"
}
]
}
},
https://github.com/angular/angular-cli/blob/main/packages/angular_devkit/architect/builders/builders.json#L14-L23 https://github.com/angular/angular-cli/blob/main/packages/angular_devkit/architect/builders/builders.json#L14-L23
allOf
runs each target at the same time allOf
运行每个目标concat
runs them serially concat
连续运行它们
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.