VisualStudioCodeでgulpを動かす時、ルートディレクトリ以外にgulpfile.jsがある場合の設定方法
VisualStudioCodeはgulpなどのタスクツールをエディタ内で動かすことができるけど、 gulpfile.jsがルートディレクトリ(Codeで開いたディレクトリ)以外にある場合は、追加設定が必要。
手順
- (Macの場合)⌘+Shift+Pを同時押しでコマンドパレットを開く。
- "task"まで入力して「タスクランナーの構成」でEnter。
- 「gulp」を選択。(ここまでは通常通り)
- タスクランナーの構成に「options」を追加し、その中のcwdでgulpfile.jsが存在するパスを指定する。
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "0.1.0", "command": "gulp", "isShellCommand": true, "args": ["--no-color"], ///////////////////////// "options": { "cwd" : "${workspaceRoot}/js_sample" // workspaceRootはCodeで開いたディレクトリ }, ////////////////////////// "showOutput": "always"
- もう一度コマンドパレットを開いて、"task"まで入力して「タスクの実行」でEnter。
- gulpfile.jsに定義されたタスクの一覧が表示されるので、使いたいものを選ぶ。