可以将Visual Studio代码配置为启动电子

nsx*_*vid 10 electron visual-studio-code

由于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": { }
    }, 
Run Code Online (Sandbox Code Playgroud)

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

有什么想法吗?

Sha*_*ski 18

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

{
    "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"
}, 
Run Code Online (Sandbox Code Playgroud)

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


And*_*and 1

理论上,以下内容应该有效:\n将 electro.exe 指定为“runtimeExecutable”(因为它取代了节点运行时)。电子程序(“CrawlSpace_Electron\\”)成为“程序”。VSCode 自动将“--debug-brk”或“--debug”传递给 Electron.exe。\n实际上 VSCode 尚不支持此设置,因为 VSCode 的预览版本会尝试验证“program”属性是否是一个文件存在于磁盘上。但对于 Electron 来说,“程序”必须是一个目录。\n我在我们这边创建了一个错误,并将确保它\xe2\x80\x99s 在下一个版本中修复。

\n