Skip to content

调试工具

v5 可以非常方便的使用 IDE 的 debuger,无论是 js,还是 ts,都能方便进行调试。

开发者工具栏

  1. 在启动的应用程序界面,菜单中找到 view -> toggle developer tool ,点击打开:控制台工具。

  2. 在配置中开启 开发者工具

debug

debug配置文件

需要添加两个vscode 配置文件:.vscode/launch.json.vscode/tasks.json

  1. 添加配置:.vscode/launch.json
json
{
  // VS Code 调试配置版本
  "version": "1.0.0",
  "configurations": [
    {
      // 仅调试主进程(需手动启动前端)
      "name": "Debug Electron",
      "type": "node",
      "request": "launch",
      "cwd": "${workspaceFolder}",
      "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
      "runtimeArgs": [
        "--inspect=9229",
        ".",
        "--env=local"
      ],
      "env": {
        "NODE_ENV": "dev"
      },
      "console": "integratedTerminal",
      "outputCapture": "std",
      "sourceMaps": true,
      "resolveSourceMapLocations": [
        "${workspaceFolder}/electron/**",
        "${workspaceFolder}/public/electron/**"
      ],
      "preLaunchTask": "ee-build-dev"
    },
    {
      // 一键启动:前端 + 主进程调试
      "name": "Debug Full App",
      "type": "node",
      "request": "launch",
      "cwd": "${workspaceFolder}",
      "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
      "runtimeArgs": [
        "--inspect=9229",
        ".",
        "--env=local"
      ],
      "env": {
        "NODE_ENV": "dev"
      },
      "console": "integratedTerminal",
      "outputCapture": "std",
      "sourceMaps": true,
      "resolveSourceMapLocations": [
        "${workspaceFolder}/electron/**",
        "${workspaceFolder}/public/electron/**"
      ],
      "preLaunchTask": "ee-dev-all"
    },
  ]
}
  1. 添加配置:.vscode/launch.tasks
json
{
  // VS Code 任务配置版本
  "version": "2.0.0",
  "tasks": [
    {
      // 构建 electron 主进程(dev 环境,含 inline sourcemap)
      "label": "ee-build-dev",
      "type": "shell",
      "command": "pnpm",
      "args": ["exec", "ee-bin", "build", "--cmds=electron", "--env=dev"],
      "group": "build",
      "problemMatcher": []
    },
    {
      // 启动前端开发服务器(后台运行)
      "label": "ee-frontend-dev",
      "type": "shell",
      "command": "pnpm",
      "args": ["dev-frontend"],
      "isBackground": true,
      "problemMatcher": {
        "pattern": { "regexp": "^$" },
        "background": {
          "activeOnStart": true,
          "beginsPattern": "VITE",
          "endsPattern": "ready in"
        }
      },
      "presentation": {
        "reveal": "silent",
        "panel": "shared"
      }
    },
    {
      // 复合任务:先构建 electron,再并行启动前端 + 调试主进程
      "label": "ee-dev-all",
      "dependsOn": ["ee-build-dev", "ee-frontend-dev"],
      "dependsOrder": "sequence",
      "problemMatcher": []
    }
  ]
}

其它排错方式

  • 命令行终端执行 xxx.exe (如果软件运行异常,可以通过该方式检查是否有报错)