13

由于 Visual Studio Code 是使用 Electron 创建的,我猜可能将 launch.json 配置为使用 Electron 正确启动应用程序。但我还没想好怎么做。

另外,由于 Electron 基于 io.js,它本身基于 Node.js,我想也许……可以做到,但还没有找到神奇之处。

尝试了这些方面的东西......来自launch.json的片段:

"configurations": [
    {
        // Name of configuration; appears in the launch configuration drop down menu.
        "name": "Launch Electron",
        // Type of configuration. Possible values: "node", "mono".
        "type": "node",
        // Workspace relative or absolute path to the program.
        "program": "Y:\\dev\\electron\\electron.exe",
        // Automatically stop program after launch.
        "stopOnEntry": false,
        // Command line arguments passed to the program.
        "args": ["CrawlSpace_Electron\\"],
        // Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
        "cwd": ".",
        // Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
        "runtimeExecutable": null,
        // Environment variables passed to the program.
        "env": { }
    }, 

它确实启动了 Electron,但失败了(窗口消失得太快,无法确切了解原因)。

有什么想法吗?

4

5 回答 5

23

如果您将 electron.exe 指定为 runtimeExecutable(如前所述),您可以将 main.js 文件作为程序传递,它将起作用。Electron 允许您指定目录main.js 文件,因为这几乎就是 package.json 指向的内容。在我的 launch.json 文件中使用下面的配置,按 F5 既可以使用我的应用程序启动 Electron,也可以将调试器连接到主进程(最终)...

{
    "name": "Launch Electron",
    "type": "node",
    "program": "${workspaceRoot}/app/main.js", // ensure this is path to main.js file
    "stopOnEntry": false,
    "args": [], 
    "cwd": "${workspaceRoot}",
    // as you have noted, this is also important:
    "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
}, 

我的 main.js 文件位于我通常会传递给 Electron 的 app 文件夹中。

于 2015-06-03T02:42:38.740 回答
3

是的,它可以。VSCode 不仅可以启动 Electron,还可以调试它。

使用node你可以调试 Electron 的 Main 进程,但使用Debugger for Chrome你也可以调试 Electron 的 Renderer 进程。我写了一篇关于这个主题的博客文章:http: //code.matsu.io/1

当前投票率最高的答案有点过时了。

这是两个预配置的项目:https ://github.com/octref/vscode-electron-debug 。

这是launch.json第一个项目。要运行目标“调试渲染器进程”,您需要安装Debugger for Chrome。但是“调试主进程”在香草 VSCode 上运行良好。

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug Main Process",
      "type": "node",
      "request": "launch",
      "cwd": "${workspaceRoot}",
      "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
      // Use the following for Windows
      // "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd",
      "program": "${workspaceRoot}/main.js"
    },
    {
      "name": "Debug Renderer Process",
      "type": "chrome",
      "request": "launch",
      "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
      // Use the following for Windows
      // "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd",
      "runtimeArgs": [
        "${workspaceRoot}/main.js",
        "--remote-debugging-port=9222"
      ],
      "webRoot": "${workspaceRoot}"
    }
  ]
}
于 2016-09-19T02:10:42.700 回答
1

理论上,以下应该起作用:将 electron.exe 指定为“runtimeExecutable”(因为它替换了节点运行时)。电子程序(“CrawlSpace_Electron”)成为“程序”。VSCode 自动将“--debug-brk”或“--debug”传递给 electron.exe。实际上 VSCode 还不支持这种设置,因为 VSCode 的预览版会尝试验证“程序”属性是否是存在于磁盘上的文件。但是对于电子,“程序”必须是一个目录。我在我们这边创建了一个错误,并将确保它在下一个版本中得到修复。

于 2015-05-11T10:48:32.693 回答
1

我知道这只是 1 个链接,但这是每个人都需要的答案...

https://code.visualstudio.com/docs/editor/debugging#_launchjson-attributes

以下是为launch.json. 不确定列表当前是否完整,但它至少应该有所帮助......

于 2020-08-29T05:17:57.977 回答
0

在 OSX 上,电子的路径是

"runtimeExecutable": "${workspaceRoot}/node_modules/electron-prebuilt/dist/Electron.app/Contents/MacOS/Electron",
于 2016-09-10T19:52:38.393 回答