vscode 타입스크립트 간단한 launch.json

벨붕·2022년 4월 23일
0

타입스크립트 프로젝트에서 보일러플레이트를 사용하지 않고 단순히

console.log("Hello World!")

를 사용하려고 해도 launch.json를 작성하기 막막할 때가 있다.

이럴땐 프로젝트에서 (npm init를 한 폴더라든지)

typescript
ts-node

위 2개를 dev-dependency에 깔아주고

.vscode/launch.json 에 configurations에다가

    {
      "name": "Launch via ts-node",
      "type": "node",
      "protocol": "inspector",
      "request": "launch",
      "runtimeExecutable": "node",
      "runtimeArgs": [
        "--nolazy",
        "-r",
        "ts-node/register/transpile-only"
      ],
      "args": [
        "src/index.ts",
        "--debug",
      ],
      "cwd": "${workspaceRoot}",
      "internalConsoleOptions": "neverOpen",
      "console": "integratedTerminal",
      "skipFiles": [
        "<node_internals>/**",
        "node_modules/**"
      ],
      "env": {
        "DEBUG": "debug:*",
      }
    }

를 추가해서 돌리면 편하게 쓸 수 있다.

src/index.ts 부분을 자신이 원하는 맨 처음 파일로 지정해주면 되고
ts-node/register/transpile-only 부분은 에러 체크를 하지 않기 때문에 만약 에러 체크를 한다면 지워두는게 좋다.

DEBUG 부분은 debug 모듈 쓸 때 바꾸자.

  • 예시로 launch.json 을 적으면 이렇게 생긴다.
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch via ts-node",
      "type": "node",
      "protocol": "inspector",
      "request": "launch",
      "runtimeExecutable": "node",
      "runtimeArgs": [
        "--nolazy",
        "-r",
        "ts-node/register/transpile-only"
      ],
      "args": [
        "src/index.ts",
        "--debug",
      ],
      "cwd": "${workspaceRoot}",
      "internalConsoleOptions": "neverOpen",
      "console": "integratedTerminal",
      "skipFiles": [
        "<node_internals>/**",
        "node_modules/**"
      ],
      "env": {
        "DEBUG": "debug:*",
      }
    }
  ]
}

profile
코딩 초보 겸 게이머

0개의 댓글