英文:
TurboRepo, run only some workspaces
问题
这是我的工作空间结构:
- 应用程序
- web-1(next)
- web-2(next)
- web-3(next)
- 包
- pack-1(UI)
- pack-2(React 工具)
- pack-3(Node 工具)
- 服务
- service-1(Express)
- service-2(Express)
- service-3(Express)
- service-4(Express)
我希望能够运行 "run dev:web-1"、"run dev:web-2" 或 "run dev:web-3",在这些情况下,始终所有的包都可用,但只包括一个或两个服务。
如果我现在运行 "yarn dev",所有内容都会启动,我实际上必须将 --concurrency 设置为较高的值,我不想这样做。
英文:
this is my structure of workspaces:
- apps
- web-1 (next)
- web-2 (next)
- web-3 (next)
- packages
- pack-1 (ui)
- pack-2 (react utils)
- pack-3 (node utils)
- services
- service-1 (express)
- service-2 (express)
- service-3 (express)
- service-4 (express)
I want to be able to run "run dev:web-1" , or "run dev:web-2" or "run dev:web-3"
in which
always ALL the packages are available
one or 2 of the services are included
If I run "yarn dev" right now, everything fires up and i actually had to set the --concurrency to a higher value and i don't want to be doing that.
答案1
得分: 2
"Ok, so after a longer look into the documentation, i found the --filter flag
can be set several times on the turbo run
command. So, my solution was to add scripts to my main package.json
"scripts": {
"build": "turbo run build",
"dev": "turbo run dev",
"lint": "turbo run lint",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"dev:web-1": "turbo run dev --filter=web-1 --filter=service-2 --filter=service-3",
"dev:screen": "turbo run dev --filter=web-2 --filter=service-1"
},
英文:
Ok, so after a longer look into the documentation, i found the --filter flag
can be set several times on the turbo run
command. So, my solution was to add scripts to my main package.json
"scripts": {
"build": "turbo run build",
"dev": "turbo run dev",
"lint": "turbo run lint",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"dev:web-1": "turbo run dev --filter=web-1 --filter=service-2 --filter=service-3",
"dev:screen": "turbo run dev --filter=web-2 --filter=service-1"
},
答案2
得分: 1
为了实现在确保所有软件包可用并包含一两个服务的情况下运行特定开发脚本以用于Web应用程序的期望行为,您可以使用Yarn工作区和像npm-run-all或concurrently这样的脚本管理工具。
要做到这一点,您需要安装必要的依赖项:
yarn add -D npm-run-all
更新根目录下的package.json文件以包括开发脚本:
"scripts": {
"dev:web-1": "cd apps/web-1 && yarn dev",
"dev:web-2": "cd apps/web-2 && yarn dev",
"dev:web-3": "cd apps/web-3 && yarn dev",
"dev:services": "run-p dev:service-1 dev:service-2",
"dev:service-1": "cd services/service-1 && yarn dev",
"dev:service-2": "cd services/service-2 && yarn dev",
"dev:all": "run-p dev:packages dev:web-1 dev:web-2 dev:web-3 dev:services",
"dev:packages": "yarn workspace pack-1 dev && yarn workspace pack-2 dev && yarn workspace pack-3 dev"
}
在各自的apps/web-X和services/service-X目录中,请确保在它们各自的package.json文件中正确定义了yarn dev脚本。
现在,您可以运行以下命令:
yarn dev:web-1 启动web-1的开发服务器。
yarn dev:web-2 启动web-2的开发服务器。
yarn dev:web-3 启动web-3的开发服务器。
yarn dev:services 启动service-1和service-2的开发服务器。
yarn dev:all 启动所有开发服务器,包括Web应用程序和所选的服务。
通过分离每个Web应用程序和服务的特定开发脚本,并使用像npm-run-all或concurrently这样的脚本管理工具,您可以控制运行不同服务的并发性,并确保所有必需的软件包可用。
请根据您的具体项目结构和配置更新脚本和文件路径。
英文:
To achieve the desired behavior of running specific development scripts for web applications while ensuring that all packages are available and one or two services are included, you can use Yarn workspaces and a script management tool like npm-run-all or concurrently.
To do that you need to install the necessary dependencies:
<!-- Language: lang-bash -->
yarn add -D npm-run-all
> > Update your package.json file in the root directory to include the dev scripts:
json
<!-- Language: lang-json -->
"scripts": {
"dev:web-1": "cd apps/web-1 && yarn dev",
"dev:web-2": "cd apps/web-2 && yarn dev",
"dev:web-3": "cd apps/web-3 && yarn dev",
"dev:services": "run-p dev:service-1 dev:service-2",
"dev:service-1": "cd services/service-1 && yarn dev",
"dev:service-2": "cd services/service-2 && yarn dev",
"dev:all": "run-p dev:packages dev:web-1 dev:web-2 dev:web-3 dev:services",
"dev:packages": "yarn workspace pack-1 dev && yarn workspace pack-2 dev && yarn workspace pack-3 dev"
}
In the respective apps/web-X and services/service-X directories, ensure that the yarn dev scripts are properly defined in their respective package.json files.
Now you can run the following commands:
> yarn dev:web-1 to start the development server for web-1.
> yarn dev:web-2 to start the development server for web-2.
> yarn dev:web-3 to start the development server for web-3.
> yarn dev:services to start the development servers for service-1 and service-2.
> yarn dev:all to start all development servers, including the web applications and selected services.
By separating the specific development scripts for each web application and services, and using a script management tool like npm-run-all or concurrently, you can control the concurrency of running the different services and ensure that all the required packages are available.
Remember to update the scripts and file paths according to your specific project structure and configurations.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论