2017-04-27 56 views
7

我一直在翻阅文档of visual studio code以了解如何将多个连续任务添加到tasks.json文件。如何仅使用tasks.json链接Visual Studio代码中的任务?

'tasks'数组只允许为同一个命令创建不同的参数。在这个例子中,命令是'echo'。

{ 
    "version": "0.1.0", 
    "command": "echo", 
    "isShellCommand": true, 
    "args": [], 
    "showOutput": "always", 
    "echoCommand": true, 
    "suppressTaskName": true, 
    "tasks": [ 
     { 
      "taskName": "hello", 
      "args": ["Hello World"] 
     }, 
     { 
      "taskName": "bye", 
      "args": ["Good Bye"] 
     } 
    ] 
} 

tasks.json是否允许连续执行多个任务?例如,tsc,然后是uglify

+0

同样的问题.. – tBlabs

+0

同样在这里,应该是不错的连锁任务莫名其妙 – pouya

+1

在VS代码我不的最新版本”不再使用tasks.json。你可以把你的命令放在'package.json'中的'scripts'标签下。如果你只需要两三个连续的命令,你可以使用'pre'和'post'标签。如果你的构建过程变得更复杂,你可以使用gulp或webpack。 – Kokodoko

回答

5

dependsOn功能在版本1.10.0(release notes)中发货。例如,我用这来编译和运行打字稿单个文件的脚本:这里

{ 
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format 
    "version": "2.0.0", 
    "tasks": [ 
     { 
      "command": "tsc -p ${cwd}/2017-play", 
      "taskName": "tsc-compile", 
      "type": "shell" 
     }, 
     { 
      "command": "node ${cwd}/2017-play/build/${fileBasenameNoExtension}.js", 
      "taskName": "node-exec", 
      "type": "shell", 
      "dependsOn": [ 
       "tsc-compile" 
      ], 
      "problemMatcher": [] 
     } 
    ] 
} 
+0

这是一个巨大的进步!但我仍然认为MS的文档对如何使用'tasks.json'非常不清楚。通过这一点,我放弃了,只是使用'npm脚本'或'webpack' – Kokodoko

+0

这应该被接受回答@Kokodoko – R2RT

相关问题