0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

VSCodeのタスクを理解しよう

0
Posted at

はじめに

VSCodeには「タスク機能」という、繰り返し実行するコマンドを登録・呼び出せる仕組みがあります。
ビルド・テスト・ファイル変換など、毎回ターミナルに打ち込む作業を自動化できます。
この記事は自分の理解を整理するための学習メモです。同じところで詰まっている方の参考になれば幸いです。

tasks.json の場所

tasks.json はワークスペースルートの .vscode/ フォルダ内に配置します。

ワークスペースルート/
└── .vscode/
    └── tasks.json

tasks.json の作成方法

コマンドパレットから自動生成できます。

  1. Ctrl+Shift+P でコマンドパレットを開く
  2. 「タスク: タスクの構成」を選択する
  3. .vscode/tasks.json が自動生成される

tasks.json の基本構成

生成された tasks.json に、実行したいコマンドを追加します。

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "ビルド",
      "type": "shell",
      "command": "npm run build",
      "group": "build"
    }
  ]
}
フィールド 説明
label タスクの名前(実行時に一覧に表示される)
type "shell" を指定するとターミナルでコマンドを実行する
command 実行するコマンド
group "build""test" など、タスクの種別

タスクの実行方法

  1. Ctrl+Shift+P でコマンドパレットを開く
  2. 「タスク: タスクの実行」を選択する
  3. 登録したタスク名(例: 「ビルド」)を選ぶ

まとめ

  • tasks.json.vscode/ 以下に配置する
  • コマンドパレットの「タスクの構成」で自動生成できる
  • label / type / command の3つが最小構成
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?