可以将 Visual Studio Code 配置为启动电子吗 [英] Can Visual Studio Code be configured to launch electron

查看:18
本文介绍了可以将 Visual Studio Code 配置为启动电子吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Since Visual Studio Code was created using Electron, I'm guessing that launch.json might be configured to properly launch an app using Electron. But I've not figured out how to do it yet.

另外,由于 Electron 是基于 io.js,它本身基于 Node.js,我想也许……可以做到,但还没有找到魔力.

Also since Electron is based on io.js, itself based on Node.js, I'm thinking maybe... it can be done, but haven't found the magic yet.

尝试了一些类似的东西...来自launch.json的片段:

Tried something along these lines... snippet from 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,但是失败了(窗口消失得太快,看不出确切的原因).

It does start Electron, but fails (window vanishes too fast to see exactly why).

有什么想法吗?

推荐答案

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

If you specify electron.exe as the runtimeExecutable (as previously suggested) you can pass the main.js file as the program and it will work. Electron allows you to specify the directory OR the main.js file since that is pretty much what the package.json points to. Using the configuration below in my launch.json file, pressing F5 both launched Electron with my app and connected the debugger to the main process (eventually)...

{
    "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 文件夹中.

My main.js file is in the app folder I normally would pass to Electron.

这篇关于可以将 Visual Studio Code 配置为启动电子吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆