Using "preLaunchTasks" and Naming a Task in Visual Studio Code
So, if it's still relevant, or if someone finds this thread with the same problem, I've just figured it out how it works:
In the tasks.json, you need to create a 'tasks' array - code hint will help you with that - which holds an array of objects. Inside an object, you can have the 'taskName' key-value pair.
Example:
{
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"args": ["run-script", "webpack"],
"showOutput": "always",
"tasks": [
{
"taskName": "runwebpack",
"suppressTaskName": true
}
]
}
In my case, I had to run the npm run-script webpack
command before running my project.
In the launch.json file, the "preLaunchTask": "runwebpack"
will work now.
Note: the suppressTaskName
is true in my example. Omitting it, or setting it to false will result in VS Code appending the taskName
after the command.
A more general approach would be something like this:
{
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"args": ["run-script"],
"showOutput": "always",
"tasks": [
{ "taskName": "webpack" }
]
}
With the latter example, you can extend the tasks
array with other scripts to be run also.
Hint for my usage: npm run-script fetches what to do from the package.json file's scripts
object.
Edit: this works with VS Code 1.3.1
FWIW, I'm using VS Code 1.20.1 and here's how I got my preLaunchTask to work:
In launch.json
:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
...
"preLaunchTask": "npm: build",
}
]
}
In my package.json
:
{
...
"scripts": {
"build": "tsc"
...
}
}