vscode tasks

vscode custom task

task 模板

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Run tests",
      "type": "shell",
      "command": "./scripts/test.sh",
      "windows": {
        "command": ".\\scripts\\test.cmd"
      },
      "group": "test",
      "presentation": {
        "reveal": "always",
        "panel": "new"
      }
    }
  ]
}

解释:

  • type : shell / process -- shell 命令被解释为shell命令行, process 该命令被解释为要执行的进程。
  • command : 确切的命令
  • windows : 任何Windows特定的属性。将在Windows操作系统上执行该命令时使用,而不是使用默认属性。
  • group : 定义task所属的组,注:任意被因为 test 的组会被 run test task 运行
  • presentation : 定义如何在用户界面中处理任务输出。In this example, the Integrated Terminal showing the output is always revealed and a new terminal is created on every task run.
  • options : 覆盖默认的值 如 cwd-当前工作目录env-环境变量shell-默认shell
  • runOptions : 定义何时以及如何运行一个task

自动补全 -- ctrl+space
完整文档 : docs

shell command

对于 shell 命令需要特别对待

默认支持方式

单一命令

注意:如果命令内部有引号只能使用 单引号

{
  "label": "dir",
  "type": "shell",
  "command": "dir 'folder with spaces'"
}

单双引号 dir 'folder with spaces'

{
  "label": "dir",
  "type": "shell",
  "command": "dir",
  "args": ["folder with spaces"]
}

自己控制 quote

{
  "label": "dir",
  "type": "shell",
  "command": "dir",
  "args": [
    {
      "value": "folder with spaces",
      "quoting": "escape"
    }
  ]
}

支持的值:

  • strong : linux,macos: ' , cmd : "
  • weak : 都是 "

compound task

使用 dependsOn 将任务组合

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Client Build",
      "command": "gulp",
      "args": ["build"],
      "options": {
        "cwd": "${workspaceFolder}/client"
      }
    },
    {
      "label": "Server Build",
      "command": "gulp",
      "args": ["build"],
      "options": {
        "cwd": "${workspaceFolder}/server"
      }
    },
    {
      "label": "Build",
      "dependsOn": ["Client Build", "Server Build"]
    }
  ]
}

如果使用了 "dependsOrder": "sequence" 那么任务就会按照顺序进行。

{
  "label": "One",
  "type": "shell",
  "command": "echo Hello ",
  "dependsOrder": "sequence",
  "dependsOn": ["Two", "Three"]
}

Tasks: Open User Tasks : 打开全局task

output and run behavior

vscode-output
vscode-input

Variable substitution

默认变量替换 vscode-docs

注意: command, args, options 这三个属性的值可以使用变量替换

[[vscode variable substitution]]

操作系统特定属性

{
  "label": "Run Node",
  "type": "process",
  "windows": {
    "command": "C:\\Program Files\\nodejs\\node.exe"
  },
  "linux": {
    "command": "/usr/bin/node"
  }
}
  • window : windows
  • linux : linux
  • macos : osx

global task

vscode-global task

部分案例 -- scss typescript

vsocde - examples

problem matcher, multiline problem matacher

vscode - problem matcher

background/watching tasks

Some tools support running in the background while watching the file system for changes and then triggering an action when a file changes on disk.

  • tsc --watch
  • npm dev

vscode

创建问题

选择 terminal

options.shell.executable

见文档

作者:bigsharker

出处:https://www.cnblogs.com/bigsharker/p/18198550

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

posted @   big_shark  阅读(47)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
more_horiz
keyboard_arrow_up light_mode palette
选择主题
点击右上角即可分享
微信分享提示