您可以这样做,但需要进行一些修改。
launch.json
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach to Remote",
"address": "127.0.0.1",
"port": 9229,
"localRoot": "${workspaceRoot}",
"remoteRoot": "/usr/src/app",
"preLaunchTask": "start_node_compose"
}
// {
// "type": "node",
// "request": "launch",
// "name": "Launch Program",
// "program": "${workspaceRoot}/index.js"
// }
]
}
如您所见,我评论了本地发布并将其设为第一个,因此它在 F5 上运行。接下来我们需要定义一个start_node_compose任务
tasks.json
{
"version": "0.1.0",
"command": "myCommand",
"isShellCommand": false,
"args": [],
"showOutput": "always",
"tasks": [
{
"taskName": "start_node_compose",
"showOutput": "always",
"isBuildCommand": true,
"command": "/bin/bash",
"args": [
"-c",
"docker-compose -f docker-compose.yml -f docker-compose.debug.yml up -d && sleep 10"
]
}
]
}
然后,当你使用 F5 运行命令时,你将能够命中断点