Define multiple tasks in VSCode

后端 未结 13 2096
旧时难觅i
旧时难觅i 2020-11-28 05:40

I have seen that it is possible to define a task in the VSCode. But I am not sure how to define multiple tasks in the tasks.json file.

13条回答
  •  囚心锁ツ
    2020-11-28 06:15

    Just in case it helps someone... . If you don't have/want gulp/grunt/etc... or an extra shell script to proxy out your task commands , "npm run" is there already .

    this is for webpack and mocha as in "Build and Test" , Shift+Ctrl+B, Shift+Ctrl+T

    .vscode/tasks.json:

    {
      "name": "npmTask",
      //...
      "suppressTaskName": true,
      "command": "npm",
      "isShellCommand": true,
      "args": [
        "run"
      ],
      "tasks": [
        {
          //Build Task
          "taskName": "webpack",
          //Run On Shift+Ctrl+B
          "isBuildCommand": true,
          //Don't run when Shift+Ctrl+T
          "isTestCommand": false,
          // Show the output window if error any
          "showOutput": "silent",
          //Npm Task Name
          "args": [
            "webpack"
          ],
          // use 2 regex:
          // 1st the file, then the problem       
          "problemMatcher": {
            "owner": "webpack",
            "severity": "error",
            "fileLocation": "relative",
            "pattern": [
              {
                "regexp": "ERROR in (.*)",
                "file": 1
              },
              {
                "regexp": "\\((\\d+),(\\d+)\\):(.*)",
                "line": 1,
                "column": 2,
                "message": 3
              }
            ]
          }
        },
        {
          //Test Task   
          "taskName": "mocha",
          // Don't run on Shift+Ctrl+B
          "isBuildCommand": false,
          // Run on Shift+Ctrl+T
          "isTestCommand": true,
          "showOutput": "always",
          "args": [
            "mocha"
          ]
        }
      ]
    }
    

    package.json:

    {
      ...
      "scripts": {
        "webpack": "webpack",
        "mocha": "/usr/bin/mocha"
      },
      ...
    }
    

提交回复
热议问题