【问题标题】:How to use cpx when debugging in VS Code?在 VS Code 中调试时如何使用 cpx?
【发布时间】:2018-06-14 14:28:30
【问题描述】:
我想使用cpx 作为我在 Visual Studio Code 中的一个调试配置的后台任务。但是它没有输出并导致此错误:
因为 cpx 在不到一秒的时间内完成了它的工作,所以我不需要跟踪它。有没有办法告诉 VS Code 只是运行任务而不是跟踪它?
这是我的tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"script": "cpx",
"type": "npm",
"isBackground": true
}
]
}
【问题讨论】:
标签:
visual-studio-code
vscode-tasks
vscode-debugger
【解决方案1】:
如果您只想执行一次任务,只需设置isBackground: false。
否则,在 Visual Studio Code 启动调试器之前,它需要知道后台任务何时完成其初始工作。它是通过使用问题匹配器观察任务输出而发生的,但正如您所指出的,cpx 默认情况下不输出任何内容。这是我的建议:
- 将
--verbose 标志传递给cpx,这给了我们一些以Be watching... 结尾的输出
- 对您的任务使用以下问题匹配器:
{
"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
}
]
}
}
]
}