2016-03-02 47 views
2

我想並行運行2個npm腳本,但是這個VS代碼只運行第一個任務並停在那裏。我該如何解決它? 我tasks.json是如下:如何在VS代碼中運行2個監視任務?

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

回答

0

我不相信你可以兩者同時進行的任務。相反,你可以從npm做到這一點。

在tasks.json文件:

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

在的package.json文件,如果你使用的是Windows:

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

在的package.json文件,如果你是在Unix/Linux/mac:

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

在Windows中是否正確?得到了如下的錯誤: > babel; gulp ▀╢░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ;不存在。吞噬不存在 ▀╢░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ – Rwing

+0

對不起,錯字。固定在上面。 – nullcable

+1

仍然不能,也許'&'符號不能在windows中工作,ref:http://stackoverflow.com/questions/31387347/windows-bash-and-sign-to-run-parallel-processes – Rwing

0

在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代碼可以在狀態欄中顯示正在旋轉的'\')。

相關問題