{"version": "0.2.0","configurations": [{"type": "node","request": "launch","name": "Launch","program": "${workspaceRoot}/index.js"},{"type": "node","request": "attach","name": "Attach","port": 5858}]}
其中最重要的参数是 request ,它的取值有两种 launch 和 attach。
"version": "0.2.0","configurations": [{"type": "chrome","request": "launch","name": "Launch index.html","sourceMaps": true,"file": "${workspaceRoot}/index.html"},]}
在 tsconfig.json 中 打开 sourceMap
{"compilerOptions": {"module": "commonjs","target": "es5","noImplicitAny": true,"outDir": "./dist","sourceMap": true},"include": ["src/**/*"]}
配置自动编译 添加或编辑文件 /.vscode/launch.json
{"version": "0.2.0","configurations": [{"name": "launch","type": "node","request": "launch","program": "${workspaceRoot}/dist/main.js","args": [],"cwd": "${workspaceRoot}","protocol": "inspector"}]}
注意 : program 需设置为你要调试的 ts 生成的对应的 js。 假如需要调试 /src/main.ts,则此处为 ${workspaceRoot}/dist/main.js。 调试 打开 main.ts,在左侧添加断点,进行调试。
npm install typescript --save-devnpm install ts-node --save-dev
{"compilerOptions": {"module": "commonjs","target": "es5","noImplicitAny": true,"outDir": "./dist","sourceMap": true //主要是这个配置},"include": ["src/**/*"]}
{"compilerOptions": {"module": "commonjs","target": "es5","noImplicitAny": true,"outDir": "./dist","sourceMap": true},"include": ["src/**/*"]}