简体   繁体   English

Nx CLI 运行许多命令不适用于多个应用程序

[英]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

Github Github

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 月更新解决方案。

  1. 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"

  2. inside apps folder, there are several application, and go to their package.json , and edit `targets -> serve -> options like this sampleapps文件夹中,有几个应用程序,以及 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.

相关问题 如何使用 Azure 和 NX 部署多个应用程序 (monorepo) - How to deploy multiple apps (monorepo) with Azure and NX Nrwl Nx 和 monorepo - 处理特定应用程序的 package.json - Nrwl Nx and monorepo - handle package.json for particular apps NX Cypress 在 GitHub 操作上运行两次 - NX Cypress run twice on the GitHub Action 为什么运行Nrwl nx cli时会出现这个错误? - Why does this error appear when running Nrwl nx cli? 如何通过 nxfluence:test 将参数传递给 ng-cli? - How to pass arguments to ng-cli through nx affected:test? 如何在 Gitlab CI Runner 中构建 Nx monorepo 应用程序 - How to build Nx monorepo apps in Gitlab CI Runner 用于非 js 应用程序 (php) 的 Lerna / Nx / Turborepo 或其他 monorepo 系统 - Lerna / Nx / Turborepo or other monorepo systems for non-js apps (php) nx build 命令因 TypeError 失败:无法读取未定义的属性(读取“云”) - nx build command failed with TypeError: Cannot read properties of undefined (reading 'cloud') 使用 Nrwl Nx Mfa 工作区添加 @angular/material 时,在 apps/product/src/main.ts 中找不到 bootstrapApplication 调用 - Could not find bootstrapApplication call in apps/product/src/main.ts while adding @angular/material with Nrwl Nx Mfa Workspace Nx Angular - 没有这样的文件或目录,打开 'd:\...\TheApp\Source\Angular.Apps/apps/app-client/src/environments/environment.prod.ts' - Nx Angular - no such file or directory, open 'd:\...\TheApp\Source\Angular.Apps/apps/app-client/src/environments/environment.prod.ts'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM