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

前端 未结 6 1654
野的像风
野的像风 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条回答
  •  萌比男神i
    2021-01-31 14:58

    For version 2.0.0 configuration you now use label instead of taskName.

    package.json:

    ...
    "scripts": {
        "tsc": "tsc",
        ...
    }
    ...
    

    launch.json (My source is in the src directory and tsc compiles to the dist directory):

    {
        "version": "0.2.0",
        "configurations": [
            {
                "type": "node",
                "request": "launch",
                "preLaunchTask": "Compile",
                "name": "Launch Program",
                "program": "${workspaceFolder}/src/index.ts",
                "outFiles": [
                    "${workspaceFolder}/dist/**/*.js"
                ],
                "protocol": "inspector",
                "sourceMaps": true
            }
        ]
    }
    

    tasks.json:

    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "Compile",
                "type": "npm",
                "script": "tsc",
                "problemMatcher": []
            }
        ]
    }
    

提交回复
热议问题