According to the documentation, it is possible to launch a program before debugging:
To launch a task before the start of each debug session, set the
For vscode 1.36.1 (1.36.1)
:
tasks.json
:
{
"version": "2.0.0",
"tasks": [
{
"label": "build:tsc",
"type": "npm",
"script": "build:tsc"
},
{
"label": "clean",
"type": "npm",
"script": "clean"
},
{
"label": "build",
"dependsOrder": "sequence",
"dependsOn": ["clean", "build:tsc"]
}
]
}
launch.json
:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/dist/main.js",
"preLaunchTask": "build",
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
"console": "integratedTerminal"
}
]
}
Before running node ${workspaceFolder}/dist/main.js
, the preLaunchTask
will run build
task firstly which includes two subtasks: clean
and build
. It will run clean
task firstly, then run build
task.
You can specify the label of a task to preLaunchTask
option.