tasks.json turns your build and test commands into VS Code actions you can trigger from the Command Palette or wire into the debugger.
A default build task
Mark one task as the default build so Ctrl/Cmd+Shift+B just runs it:
{
"label": "build",
"type": "shell",
"command": "npm run build",
"group": { "kind": "build", "isDefault": true },
"problemMatcher": ["$tsc"]
}
The problemMatcher parses compiler output into the Problems panel.
Background watch tasks
Long-running watchers set isBackground and a watch matcher so errors surface as you type:
{ "label": "watch", "type": "shell", "command": "npm run watch", "isBackground": true, "problemMatcher": ["$tsc-watch"] }
Chain tasks with dependsOn
Compose tasks instead of stringing shell commands with &&:
{ "label": "test", "type": "shell", "command": "npm test", "group": "test", "dependsOn": ["build"] }
Now running test builds first.
Ties into launch.json
A task label here is exactly what preLaunchTask in launch.json points at — so your debugger always builds before it runs.
Security notes
- Keep secrets out of
commandandargs; read them from the environment. - Be careful with tasks that auto-run on folder open (
runOptions.runOn). - Review any task that pipes untrusted input into a shell.
Open the tasks.json template and ask the workspace to "add a task that runs the linter" or "chain build then test with dependsOn", then diff the result.