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

时间:2016-03-02 08:57:33

标签: npm visual-studio-code vscode-tasks

我想并行运行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
    }
]
}

2 个答案:

答案 0 :(得分: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代码可以在状态栏中显示旋转'\')。

答案 1 :(得分:0)

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

在tasks.json文件中:

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

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

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

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

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