3

我想并行运行 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
    }
]
}
4

2 回答 2

1

在 Windows 上,NPM 包“并发”可能会对您有所帮助。

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
            }
        }
    ]
}

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

于 2017-10-12T12:17:44.963 回答
0

我不相信你可以同时完成这两项任务。相反,您可以从 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"
}
于 2016-03-13T23:11:03.010 回答