4
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?

More than 3 years have passed since last update.

vscode起動時に特定の処理を実行する

Last updated at Posted at 2022-02-01

タイトルの通りです。vscodeでプロジェクトを開くと自動で何かしらの初期化処理を実行させたり、開発用サーバーを起動したりする方法を調べたので書き残します。

やり方

vscodeのタスク機能を使います。今回は以前の記事で作成したこちらのリポジトリのdocker-composeを自動で起動していきます。

プロジェクト直下に.vscode/tasks.jsonファイルを作成する

tasks.json
{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Launch PlantUML Server",
      "type": "docker-compose", // 他にshell, processなどが使えます
      "dockerCompose": {
        "up": {
          "detached": true,
          "build": true
        },
        "files": ["${workspaceFolder}/docker-compose.yml"]
      },
      "group": "none",
      "presentation": {
        "reveal": "always",
        "panel": "new"
      },
      "runOptions": {
        "runOn": "folderOpen"
      }
    }
  ]
}

vscodeの設定で自動タスクを許可する

command+shift+p(ctrl+shift+p)でTasks: Manage Automatic Tasks in Folderを選択
スクリーンショット 2022-02-02 0.42.08.png

Allow Automatic Tasks in Folderを選択
スクリーンショット 2022-02-02 0.44.46.png

vscodeでプロジェクトを開き直す

無事自動でdocker-compose up -dが実行されたかと思います。
以上です!

4
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
4
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?