VS Code Prelaunch Tasks

To create a prelaunch task in Visual Studio Code, follow these steps:

  1. Open the Command Palette (Ctrl+Shift+P on Windows or Shift+Command+P on Mac).
  2. Type “task” and select “Tasks: Configure Task Runner”. This will create a tasks.json file in your project.
  3. In the tasks.json file, you can define a task that runs before launch by adding a property called isBackground and setting it to true. For example:
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "gulp build",
            "isBackground": true,
            "problemMatcher": []
        }
    ]
}
  1. You can then bind this task to the launch command by adding a preLaunchTask property to your launch configuration in launch.json. For example:
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "preLaunchTask": "build",
            "program": "${workspaceFolder}/index.js"
        }
    ]
}

This will cause the task to run before the launch command every time you debug your program.



Categories: Developer Chat

Tags: , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: