vscode ssh 使用launch.json进行调试
时间: 2024-10-17 09:12:37 浏览: 43
Visual Studio Code (VSCode) 中的 SSH 调试功能允许开发者通过 SSH 连接到远程服务器并在那里运行和调试代码,无需直接在本地环境中模拟整个服务器环境。这通过使用 `launch.json` 文件配置来实现,它是 VSCode 调试配置的一种标准化格式。
以下是基本步骤:
1. **设置launch.json**:
- 在项目根目录下,打开 `.vscode` 文件夹,找到并编辑 `launch.json` 文件。
- 创建一个新的配置项,例如:
```
{
"name": "SSH Debug",
"type": "node",
"request": "launch",
"remote": {
"host": "<your_server_ip>",
"port": <ssh_port>,
"path": "${workspaceFolder}",
},
"program": "${workspaceFolder}/your_entrypoint.js", // 或者你的主文件路径
"sourceMapPathOverrides": {
"webpack:///src/*": "${fileDirname}/${relativeFile}"
}
}
```
其中 `<your_server_ip>` 和 `<ssh_port>` 需要替换为你实际的服务器地址和端口号。
2. **启动调试**:
- 在 VSCode 内,点击 Debug 视图(快捷键 F5),选择 "SSH Debug",然后输入用户名和密码连接到服务器。
- 如果一切设置正确,VSCode 就会在远程服务器上启动你的应用,并提供了一个交互式的调试界面。
3. **断点和调试控制**:
- 在代码中设置断点(F9)。
- 调试工具允许单步执行、查看变量值、暂停和继续执行等常规调试操作。
阅读全文
相关推荐


















