vue.jsvisual-studio-codevitekey-bindings

VSCode - Vite Open Browser Shortcut


I am running Vue with Vite in VSCode on Windows 10. I have the NPM Scripts shortcuts that builds the project when clicked on. I added the following binding to keybindings.json below and works nicely to launch my site as expected:

{
    "key": "alt+g",
    "command": "workbench.action.terminal.sendSequence",
    "args": {
        "text": "npm run dev\r"
    },
},

Afterwards, I have to press the "o" to invoke the Vite "open the browser" command to launch the browser. I would like to incorporate the open command into the keybinding and I have tried several things including changing that text line to:

"text": "npm run dev\r && echo 'o'\r" 
// OR
"text": "npm run dev\r && start chrome"

Any ideas how to do that?


Solution

  • Per @startball's comment above - the following successfully compiles the project with Vite and then launches the website with the default browser.

    {
        "key": "alt+g",
        "command": "runCommands",
        "args": 
        {
          "commands":[
            {
                "command": "workbench.action.terminal.sendSequence",
                "args": { "text": "npm run dev\r" }
            },
            {
                "command": "workbench.action.terminal.sendSequence",
                "args": { "text": "o" }
            }
          ]
        }
    },