到現在爲止,我用gulp來構建打字稿和sass文件,但現在由於一些新的構建步驟,我想統一一切並使用節點作爲單個入口點通過npm run taskName運行gulp任務)。VS代碼和任務與節點
tasks.json是相當簡單的,任務build
應該運行npm run watch
:
{
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"tasks": [
{
"taskName": "build",
"isBuildCommand": true,
"showOutput": "always",
"isWatching": true,
"args": [
"run", "watch"
]
}
]
}
的package.json
"scripts": {
"watch": "gulp default",
}
和輸出:
gulp default build
[14:20:54] Using gulpfile PATH_TO/gulpfile.js
[14:20:54] Task 'build' is not in your gulpfile
[14:20:54] Please check the documentation for proper gulpfile formatting
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files (x86)\\nodejs\\\\node.exe" "C:\\Program Files (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "watch" "build"
npm ERR! node v0.12.2
npm ERR! npm v2.7.4
npm ERR! code ELIFECYCLE
npm ERR! [email protected] watch: `gulp default build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] watch script 'gulp default build'.
npm ERR! This is most likely a problem with the 2 package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! gulp default build
npm ERR! You can get their info via:
npm ERR! npm owner ls 2
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
基於輸出,即使認爲在中沒有任何跡象,吞嚥仍然有點用(gulpfile.json
存在於根目錄中,並且在搜索解決方案時發現VS Code自動檢測到它,我認爲這可能是問題所在)。此外taskName
屬性看起來像自動附加到命令行作爲一個參數是錯誤的。
較小,但工作示例(但它仍然運行一飲而盡因此打字稿是在每次保存編譯兩次):在VS代碼通過NPM
{
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"args": [
"run", "watch"
],
"showOutput": "always"
}
怎樣纔可以有多個任務與?
我正在尋找類似的解決方案。關於追加到命令行的taskName,請查找'suppressTaskName'配置屬性,如[此處]所述(http://scottaddie.com/2015/10/07/harnessing-webpack-with-visual-studio-code/) – superjos
也,看看[這個](https://dlaa.me/blog/post/vscodenodetask)來看看如何運行VS代碼 – superjos