1

I want to use cpx as a background task for one of my debugging configurations inside Visual Studio Code. However it has no output and causes this error: The task 'npm: cpx' cannot be tracked.

Since cpx does it's job in less then a second I don't need it to be tracked. Is there a way to tell VS Code just to run the task and not track it?

Here's my tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "script": "cpx",
            "type": "npm",
            "isBackground": true
        }
    ]
}
4

1 回答 1

1

如果您只想执行一次任务,只需设置isBackground: false.

否则,在 Visual Studio Code 启动调试器之前,它需要知道后台任务何时完成其初始工作。它是通过使用问题匹配器观察任务输出而发生的,但是正如您所指出的,cpx 默认情况下不输出任何内容。这是我的建议:

  1. 将标志传递--verbose给 cpx,这给了我们一些以结尾的输出Be watching...
  2. 对您的任务使用以下问题匹配器:
{
    "version": "2.0.0",
    "tasks": [
        {
            "script": "cpx",
            "type": "npm",
            "isBackground": true,
            "problemMatcher": {
                "background": {
                    "activeOnStart": true, // monitoring should happen immediately after start
                    "beginsPattern": "^whatever", // irrelevant
                    "endsPattern": "^Be watching.*"  // pattern indicating that task is done
                },
                // we don't need pattern section but it's required by the schema.
                "pattern": [
                    {
                        "regexp": "^whatever",
                        "file": 1,
                        "location": 2,
                        "message": 3
                    }
                ]
            }
        }
    ]
}
于 2018-06-14T18:35:49.863 回答