Skip to content

Instantly share code, notes, and snippets.

@MichaelCurrin
Last active February 6, 2022 19:31
Show Gist options
  • Save MichaelCurrin/9cec5140edcb0c983166e8ee2c3ef0ac to your computer and use it in GitHub Desktop.
Save MichaelCurrin/9cec5140edcb0c983166e8ee2c3ef0ac to your computer and use it in GitHub Desktop.
VS Code tasks guide

Tasks

Guide for using tasks in VS Code

Tasks menu

How to open and use the tasks menu

Based on the Tasks tutorial.

Run any task

How to run a task in VS Code - use one of these approaches.

  1. Open the tasks menu using one of these approaches:
    • Keyboard shortcut
      1. Press CTRL+SHIFT+P.
    • Use the menu
      1. Open Terminal tab from the top menu bar.
      2. Click Run task....
  2. Type "Task" after ">" to search. This will narrow down the list.
  3. Select a task.

Run build task

  1. Open tasks menu, as per instructions in 1. above.
  2. Type "Build" after ">" to search. This will narrow down the list.
  3. Click Tasks: Run build task or Tasks: Configure build task.

Detection

VS Code can detect tasks for NPM, Make and other configured tools. These are available from the tasks menu.

This can be turned off with VS Code settings.

{
  "typescript.tsc.autoDetect": "off",
  "grunt.autoDetect": "off",
  "jake.autoDetect": "off",
  "gulp.autoDetect": "off",
  "npm.autoDetect": "off"
}

Configure

Command

Use the task menu.

File

Create a tasks file in your repo.

.vscode/tasks.json.

Or in your user directory.

For Linux: ~/.config/Code/User/tasks.json.

Sample task

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "echo",
            "type": "shell",
            "command": "echo Hello. This is a global VS Code task."
        }
    ]
}

NPM install and start.

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "npm",
			"script": "install",
			"problemMatcher": [],
			"label": "npm: install",
			"detail": "install dependencies from package"
		},
		{
			"type": "npm",
			"script": "start",
			"problemMatcher": [],
			"label": "npm: start",
			"detail": "docsify serve docs"
		}
	]
}

If you set the install task as the "Build" tasks (accessible via a keyboard shortcut), an extra field is added after detail.

			"group": {
				"kind": "build",
				"isDefault": true
			}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment