当前位置: 首页 > 文档资料 > Electron 中文文档 >

使用 VSCode 进行主进程调试

优质
小牛编辑
122浏览
2023-12-01

1.在 VSCode 中打开一个 Electron 项目。

$ git clone git@github.com:electron/electron-quick-start.git
$ code electron-quick-start

1. Open an Electron project in VSCode.

$ git clone git@github.com:electron/electron-quick-start.git
$ code electron-quick-start

2.添加一个 .vscode/launch.json 文件并使用以下配置:

{
  "version": "0.2.0",
  "configurations": [
    {"name": "Debug Main Process","type": "node","request": "launch","cwd": "${workspaceRoot}","runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron","windows": {  "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"},"args" : ["."],"outputCapture": "std"
    }
  ]
}

2. Add a file .vscode/launch.json with the following configuration:

{
  "version": "0.2.0",
  "configurations": [
    {"name": "Debug Main Process","type": "node","request": "launch","cwd": "${workspaceRoot}","runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron","windows": {  "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"},"args" : ["."],"outputCapture": "std"
    }
  ]
}

3. 调试

main.js中设置一些断点,并在 Debug 视图 中开始调试。你应该能够捕获断点信息。

这是一个预先配置的项目,你可以下载并直接在 VSCode中调试: https://github.com/octref/vscode-electron-debug/tree/master/electron-quick-start

3. Debugging

Set some breakpoints in main.js, and start debugging in the Debug View. You should be able to hit the breakpoints.

Here is a pre-configured project that you can download and directly debug in VSCode: https://github.com/octref/vscode-electron-debug/tree/master/electron-quick-start