vscode断点调试Typescript配置

配置

tsconfig.json

{
    "compilerOptions": {
        "module": "es6",
        "target": "es5",
        "experimentalDecorators": true,
        "noImplicitAny": false,
        "sourceMap": true,
        "pretty": true,
        "outDir": "dist"
    },

    "exclude": [
        "dist",
        "node_modules"
    ]
}

lauch.json

注意,program指向要启动的ts文件,不是js文件,outFiles则用来指定编译结果文件

{
  // Use IntelliSense to learn about possible Node.js debug attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "program": "${workspaceRoot}/app.ts",
      "outFiles": [
        "${workspaceRoot}/dist/**/*.js"
      ],
      "cwd": "${workspaceRoot}",
      "sourceMaps": true,
      "console": "integratedTerminal"
    },
    {
      "type": "node",
      "request": "attach",
      "name": "Attach to Process",
      "port": 5858,
      "outFiles": [],
      "sourceMaps": true
    }
  ]
}

示例程序

class Person{
  private first: string;
  private last: string;
  @enumerable
  name() {
    return `${this.first} ${this.last}`;
  }
}
function enumerable(target, name, descriptor: PropertyDescriptor) {
  descriptor.enumerable = true;
}

for (let key in new Person) {
  console.log(key)
}

示例代码的仓库
断点确实正常了,但是我不知道怎么让node执行js文件时也支持log的sourcemap,就像浏览器那样,懂的人指点一下

你可能感兴趣的:(vscode断点调试Typescript配置)