[英]Nx CLI run many command is not working for multiple apps
I have tried using Nx in an attempt to make use of Monorepos.我曾尝试使用 Nx 来尝试使用 Monorepos。 I have been facing an issue to serve multiple apps via
nx run-many
command.我一直面临通过
nx run-many
命令为多个应用程序提供服务的问题。 Can anyone correct me if I'm doing something wrong?如果我做错了什么,有人可以纠正我吗?
Command used: nx run-many --target=serve --all
使用的命令:
nx run-many --target=serve --all
I can see the Nx Console logging all the available apps but only running one我可以看到 Nx 控制台记录了所有可用的应用程序,但只运行了一个
> NX Running target serve for projects:
- app1
- app2
———————————————————————————————————————————————
> nx run app1:serve
Try this:尝试这个:
nx run-many --parallel --target=serve --projects=frontend,backend
nx run-many --target=serve --all --maxParallel=100
The default value for --maxParallel is three, it means runs tasks in batches of three by default. --maxParallel 的默认值为 3,表示默认以 3 个为一组运行任务。
Additional, Exclude few apps to not serve then.另外,排除一些应用程序不提供服务。
nx run-many --target=serve --all --maxParallel=100 --exclude=app-name
This happens due to port overriding, if you have multiple frontend apps for example they will run on the same port.这是由于端口覆盖而发生的,例如,如果您有多个前端应用程序,它们将在同一个端口上运行。 You can manage every project configuration in project.json file, and there you can handle different port for every project.
您可以在project.json文件中管理每个项目配置,并且可以为每个项目处理不同的端口。
example:例子:
"serve": {
"executor": "@nrwl/web:dev-server",
"options": {
"buildTarget": "react-todo:build",
"hmr": true,
"port": 3001
},
"configurations": {
"production": {
"buildTarget": "react-todo:build:production",
"hmr": false
}
}
},
this is a react config in ( apps/<Your_Project_Name>/project.json )这是( apps/<Your_Project_Name>/project.json )中的反应配置
You can change the serving port by editing package.json
您可以通过编辑
package.json
来更改服务端口
"serve": {
"executor": "@nrwl/web:dev-server",
"options": {
"buildTarget": "admin-web:build",
"port": 4220,
"hmr": true
},
"configurations": {
"production": {
"buildTarget": "admin-web:build:production",
"hmr": false
}
}
}
After that you can run nx run-many
之后你可以运行
nx run-many
nx run-many --parallel --target=serve --projects=frontend,backend
Update solution in 9/2022. 2022 年 9 月更新解决方案。
go to package.json
adding this script that allow us to run many project with only one command go 到
package.json
添加这个脚本,允许我们只用一个命令运行多个项目
"all": "npx nx run-many --target=serve --all --maxParallel=100"
inside apps
folder, there are several application, and go to their package.json
, and edit `targets -> serve -> options like this sample在
apps
文件夹中,有几个应用程序,以及 go 到他们的package.json
,并编辑 `targets -> serve -> options like this sample
"options": { "buildTarget": "your app name:build", "hmr": true, "port": 4201 // adding this },
For now, Remix uses a hardcoded 8002 port for file watcher.目前,Remix 使用硬编码的 8002 端口作为文件观察器。 When running two or more remix apps at once, either one of the apps (which was started later) would have an error accessing the file server port.
当同时运行两个或多个混音应用程序时,其中一个应用程序(稍后启动)在访问文件服务器端口时会出错。 To override, add a
.env
or .env.local
file in your respective app directory and add the environment variable REMIX_DEV_SERVER_WS_PORT
.要覆盖,请在您各自的应用程序目录中添加一个
.env
或.env.local
文件,并添加环境变量REMIX_DEV_SERVER_WS_PORT
。
apps/
- app1
.env.local -> REMIX_DEV_SERVER_WS_PORT=8003
- app2
.env.local -> REMIX_DEV_SERVER_WS_PORT=8004
This worked for me.这对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.