一种在 VSCODE 中的单独终端中打开多个脚本的方法

Lar*_*aas 7 terminal npm visual-studio-code

我需要运行几个脚本来启动我的开发环境。我更喜欢在 VSCode 中进行。

虽然使用并发等很好,但我非常希望它们在单独的终端窗口中运行,以便更轻松地跟踪任何进程的输出。

所以假设我需要跑步

npm startnpm run serve-backend,并启动两者,但在单独的终端窗口中(最好打开第三个终端窗口以供将来工作)。

vscode 有什么办法可以做到这一点吗?

Pav*_*fer 0

哦。我可能已经明白了。您可以通过任务 API ( ) 执行类似的操作.vscode/tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Dev-env",
            "type": "shell",
            "command": "echo Starting",
            "problemMatcher": [],
            "dependsOn": [
                "Backend",
                "Frontend"
            ],
        }
        {
            "type": "npm",
            "path": "backend"     
            "script": "start",
            "problemMatcher": [],
            "label": "Backend"
        },
        {
            "type": "npm",
            "script": "start",
            "path": "frontend",
            "problemMatcher": [],
            "label": "Frontend",
        },
        
    ]
}
Run Code Online (Sandbox Code Playgroud)

然后运行任务Dev-env将并行启动两个任务,每个任务都有自己的输出。( Ctrl + Shift + P=> Run Task=> Dev-env)