Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Visual Studio Code be configured to launch 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.

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.

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": { }
    }, 

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

Any thoughts?

like image 795
nsxdavid Avatar asked May 03 '15 02:05

nsxdavid


People also ask

Is VS Code running on Electron?

Using Electron, VS Code combines web technologies such as JavaScript and Node. js with the speed and flexibility of native apps. VS Code uses a newer, faster version of the same industrial-strength HTML-based editor that has powered the "Monaco" cloud editor, Internet Explorer's F12 Tools, and other projects.

What is launch configuration in VS Code?

This vscode extension allows you to create settings to launch any number of your launch. json configurations or compound configurations via separate keybindings. These launch configs can be in any root folder in a multi-root workspace.


1 Answers

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"
}, 

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

like image 192
Shawn Rakowski Avatar answered Oct 01 '22 10:10

Shawn Rakowski