如何在VS代码中运行2个监视任务?

问题描述 投票:3回答:2

我想并行运行2个npm脚本,但是这个VS代码只运行第一个任务并停在那里。我该如何解决?我的tasks.json如下:

{
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"suppressTaskName": true,
"args": [
    "run"
],
"tasks": [
    {
        "args": [
            "gulp"
        ],
        "taskName": "gulp",
        "isBuildCommand": true 
    },
    {
        "args": [
            "babel"
        ],
        "taskName": "babel",
        "isBuildCommand": true
    }
]
}
npm visual-studio-code vscode-tasks
2个回答
1
投票

在Windows上,NPM package "concurrently"可能会帮助您。

package.json

"scripts": {
   "gulpbabel": "concurrently \"npm run gulp\" \"npm run babel\""
},

然后在tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "npm",
            "script": "gulpbabel",
            "isBackground": true,
            "problemMatcher": [
                "create_one_for_gulp",
                "create_another_for_babel",
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

理想情况下(但不是必需),你还需要创建两个problem matchers:一个用于gulp任务,一个用于babel。他们应该能够从合并输出中提取错误详细信息,并检测相应任务的观察者何时触发/停止(以便VS代码可以在状态栏中显示旋转'\')。


0
投票

我不相信你可以同时完成这两项任务。相反,你可以从npm做到这一点。

在tasks.json文件中:

{
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"suppressTaskName": true,
"args": [
    "run"
],
"tasks": [
    {
        "args": [
            "gulpbabel"
        ],
        "taskName": "gulpbabel",
        "isBuildCommand": true 
    }
]
}

在package.json文件中,如果你在Windows上:

{
  "name": "stacktest",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "gulpbabel": "gulp & babel"
  },
  "author": "",
  "license": "ISC"
}

在package.json文件中,如果你在unix / linux / mac上:

{
  "name": "stacktest",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "gulpbabel": "gulp && babel"
  },
  "author": "",
  "license": "ISC"
}
© www.soinside.com 2019 - 2024. All rights reserved.