2015-11-01 9 views
10

これまではtypescriptとsassファイルをビルドするためにgulpを使用しましたが、今やいくつかの新しいビルドステップのために、すべてを統一し、単一のエントリポイントとしてノードを使用したいと思います。 npm run taskNameを使用してgulpタスクを実行します)。ノードを持つVSコードとタスク

tasks.jsonは、タスクbuildnpm 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: 

、ああ、まだ何とか使用されているにもかかわらず、それの兆候がないと思ってもtasks.jsongulpfile.jsonがルートディレクトリに存在し、ソリューションを検索しているときに、VSコードが自動的にそれを検出したことが判明しました。これは問題の可能性がありますか?)。また、taskNameプロパティは、自動的にコマンドラインに間違った引数として追加されるような外観です。

小さいが、実施例(それはまだ救うため、typescriptですが、それぞれに二回コンパイルされがぶ飲みを実行します):私は、NPMを通じてVSコード内で複数のタスクを持つことができますどのように

{ 
    "version": "0.1.0", 
    "command": "npm", 
    "isShellCommand": true, 
    "args": [ 
     "run", "watch" 
    ], 
    "showOutput": "always" 
} 

?あなたは基本的には次のように.vscode\tasks.json作成するように指示するthis articleを探し、VSコードからNPMスクリプトタスクを実行するために探しているなら、私のコメントで述べたように

+0

同様の解決策も探しています。コマンドラインに追加されたtaskNameに関しては、「suppressTaskName」の設定プロパティを参照してください。[here](http://scottaddie.com/2015/10/07/harnessing-webpack-with-visual-studio-code/) – superjos

+0

また、 、VSコード – superjos

答えて

16

:別の方法として

{ 
    "version": "0.1.0", 
    "command": "npm", 
    "isShellCommand": true, 
    "suppressTaskName": true, 
    "tasks": [ 
     { 
     // Build task, Ctrl+Shift+B 
     // "npm install --loglevel info" 
     "taskName": "install", 
     "isBuildCommand": true, 
     "args": ["install", "--loglevel", "info"] 
     }, 
     { 
     // Test task, Ctrl+Shift+T 
     // "npm test" 
     "taskName": "test", 
     "isTestCommand": true, 
     "args": ["test"] 
     }, 
     { 
     // "npm run lint" 
     "taskName": "lint", 
     "args": ["run", "lint"] 
     } 
    ] 
} 

は、ありますMicrosoftのサンプルVSコード拡張は、npmスクリプト項目を検出して実行することを特に目的としています。vscode-npm-scripts

+0

からnpmスクリプトタスクを実行する方法を知るには[this](https://dlaa.me/blog/post/vscodenodetask)を見てください。ただし、メインコマンドがnpmの場合は、どのようにtscコンパイラを実行しますか? ?すべてのタスクが独自のコマンドを持つことはできませんか? – Kokodoko

+0

申し訳ありませんが、わかりません。 grunt/gulpベースのツールチェーンをお持ちの場合は、そのタスク/手順の1つで、カバーの下でtscコンパイラを実行する必要があります。その場合、npmスクリプトからその特定のgrunt/gulpタスクを起動すると思います。私が間違っている場合はもっと明確にしてください – superjos

+0

あなたの答えをありがとう。私が正しく思い出すと、上記の解決策はうまくいきませんでした。しかし、今正解です。 –

関連する問題