gpt4 book ai didi

visual-studio-code - 是否可以从脚本内部在 VSCode 中打开一个新终端?

转载 作者:行者123 更新时间:2023-12-05 03:58:53 26 4
gpt4 key购买 nike

我想通过一个命令启动 3 个服务器。

我有这样的 package.json 脚本:

"serve_auth": "cd dev/mock/auth && nodemon --exec babel-node ./server.js --presets @babel/env",
"serve_db": "cd dev/mock/db && nodemon --exec babel-node ./server.js --presets @babel/env",
"start": "react-scripts start",
"develop": "./launch_script.sh"

我有一个脚本 launch_script.sh 如下:

#!/bin/bash

( yarn serve_db ) & ( yarn serve_auth ) & ( yarn start )

但这会在一个终端窗口中打开它们,它们最终会相互绊倒。

我知道您可以从 VSCode GUI 打开新终端,但是否可以从一个终端中打开一个新终端?或者告诉 VSCode 使用单独的命令打开 3 个终端?

最佳答案

我认为这可能是 compound tasks 的东西

{
"version": "2.0.0",
"tasks": [
{
"label": "Client Build",
"command": "gulp",
"args": ["build"],
"options": {
"cwd": "${workspaceRoot}/client"
}
},
{
"label": "Server Build",
"command": "gulp",
"args": ["build"],
"options": {
"cwd": "${workspaceRoot}/server"
}
},
{
"label": "Build",
"dependsOn": ["Client Build", "Server Build"]
}
]
}

Compound tasks
You can also compose tasks out of simpler tasks with the dependsOn property. For example, if you have a workspace with a client and server folder and both contain a build script, you can create a task that starts both build scripts in separate terminals. If you list more than one task in the dependsOn property, they are executed in parallel by default.

还有 compound launch configurations您可能会感兴趣,因为您的脚本似乎用于启动前端和后端应用程序。

{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Server",
"program": "${workspaceFolder}/server.js",
"cwd": "${workspaceFolder}"
},
{
"type": "node",
"request": "launch",
"name": "Client",
"program": "${workspaceFolder}/client.js",
"cwd": "${workspaceFolder}"
}
],
"compounds": [
{
"name": "Server/Client",
"configurations": ["Server", "Client"]
}
]
}

两者都是来自相应文档页面的示例,但根据您的脚本调整它们应该很简单。

关于visual-studio-code - 是否可以从脚本内部在 VSCode 中打开一个新终端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57600967/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com