使用 VSCode 进行主进程调试

1. Open an Electron project in VSCode.

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

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

  1. {
  2. "version": "0.2.0",
  3. "configurations": [
  4. {
  5. "name": "Debug Main Process",
  6. "type": "node",
  7. "request": "launch",
  8. "cwd": "${workspaceFolder}",
  9. "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
  10. "windows": {
  11. "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
  12. },
  13. "args" : ["."]
  14. }
  15. ]
  16. }

3. 调试

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

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