【问题标题】:how to run 2 watch tasks in VS code?如何在 VS 代码中运行 2 个监视任务?
【发布时间】:2016-03-02 08:57:33
【问题描述】:

我想并行运行 2 个 npm 脚本,但是这个 VS Code 只运行第一个任务并停在那里。我该如何解决? 我的tasks.json如下:

{
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"suppressTaskName": true,
"args": [
    "run"
],
"tasks": [
    {
        "args": [
            "gulp"
        ],
        "taskName": "gulp",
        "isBuildCommand": true 
    },
    {
        "args": [
            "babel"
        ],
        "taskName": "babel",
        "isBuildCommand": true
    }
]
}

【问题讨论】:

    标签: npm visual-studio-code vscode-tasks


    【解决方案1】:

    在 Windows 上,NPM package "concurrently" 可能会对您有所帮助。

    package.json

    "scripts": {
       "gulpbabel": "concurrently \"npm run gulp\" \"npm run babel\""
    },
    

    然后在tasks.json:

    {
        "version": "2.0.0",
        "tasks": [
            {
                "type": "npm",
                "script": "gulpbabel",
                "isBackground": true,
                "problemMatcher": [
                    "create_one_for_gulp",
                    "create_another_for_babel",
                ],
                "group": {
                    "kind": "build",
                    "isDefault": true
                }
            }
        ]
    }
    

    理想情况下(但不是必需的),您还需要创建两个problem matchers:一个用于gulp 任务,一个用于babel。他们应该能够从合并的输出中提取错误详细信息,并检测相应任务的观察者何时触发/停止(以便 VS Code 可以在状态栏中显示旋转的“\”)。

    【讨论】:

      【解决方案2】:

      我不相信你可以同时完成这两项任务。相反,您可以从 npm 执行此操作。

      在tasks.json文件中:

      {
      "version": "0.1.0",
      "command": "npm",
      "isShellCommand": true,
      "suppressTaskName": true,
      "args": [
          "run"
      ],
      "tasks": [
          {
              "args": [
                  "gulpbabel"
              ],
              "taskName": "gulpbabel",
              "isBuildCommand": true 
          }
      ]
      }
      

      如果你在 windows 上,在 package.json 文件中:

      {
        "name": "stacktest",
        "version": "1.0.0",
        "description": "",
        "scripts": {
          "gulpbabel": "gulp & babel"
        },
        "author": "",
        "license": "ISC"
      }
      

      如果您使用的是 unix/linux/mac,请在 package.json 文件中:

      {
        "name": "stacktest",
        "version": "1.0.0",
        "description": "",
        "scripts": {
          "gulpbabel": "gulp && babel"
        },
        "author": "",
        "license": "ISC"
      }
      

      【讨论】:

      • 在windows中正确吗?得到如下错误: > babel ;吞咽▀╢░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░;不存在。 gulp不存在▀╢░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
      • 对不起,错字。上面固定。
      • 还是不行,可能'&'符号在windows中不起作用,参考:stackoverflow.com/questions/31387347/…
      猜你喜欢
      • 1970-01-01
      • 2016-09-29
      • 2016-07-24
      • 1970-01-01
      • 2021-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多