Using “preLaunchTasks” and Naming a Task in Visual Studio Code

前端 未结 6 1593
野的像风
野的像风 2021-01-31 14:32

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

6条回答
  •  心在旅途
    2021-01-31 15:19

    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.

提交回复
热议问题