1、 在 VSCode 中打开一个 Electron 工程。

2、点击vscode左侧菜单栏的调试按钮

3、点击配置项下拉框,选择‘’添加配置‘’:

4、选择node.js

5、会打开launch.json配置文件

6、将原配置删除,替换如下配置并保存:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Main Process",
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
"program": "${workspaceRoot}/main.js"
}
]
}
注意: 在 Windows 中,runtimeExecutable 的参数是 "${workspaceRoot}/node_modules/.bin/electron.cmd"。program字段后面的路径是package.json指定的的主进程文件
7、在main.js中设置断点,并点击调试开始按钮开始调试

8、点击调试开始按钮,或者按下快捷键F5启动调试

9、随后就会进入断点调试,主进程就可以调试啦

网友评论