VsCode debug ts文件,VSCode调试ts文件

149 阅读1分钟

VSCode版本

1.91

package.json

{
    "type": "commonjs",
}

${PROJECT_ROOT}/tsconfig.debug.json

{
  "include": ["env.d.ts", "src/test/**/*.ts"],
  "exclude": ["src/**/__tests__/*"],
  "compilerOptions": {
    "outDir": "out",
    "sourceMap": true,
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
  },
  "ts-node": {
    "esm": true,
    "swc": true
  }
}

.vscode/tasks.json

{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "typescript",
      "tsconfig": "tsconfig.debug.json",
      "problemMatcher": ["$tsc"],
      "group": "build",
      "label": "tsc: 构建 - tsconfig.debug.json"
    }
  ]
}

.vscode/launch.json

preLaunchTask的值与tasks.jsonlabel值对应

{
  // 使用 IntelliSense 了解相关属性。
  // 悬停以查看现有属性的描述。
  // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "启动程序",
      "skipFiles": ["<node_internals>/**"],
      "program": "${workspaceFolder}\\src\\test\\demo01.ts",
      "preLaunchTask": "tsc: 构建 - tsconfig.debug.json",
      "outFiles": ["${workspaceFolder}/**/*.js"]
    }
  ]
}

进入需要调试的ts文件

>调试:开始调试

image.png

参考资料

TypeScript debugging with Visual Studio Code