Home > OS >  How to open Vite local server in specific browser?
How to open Vite local server in specific browser?

Time:12-21

I want to open my Sveltekit project in Microsoft Edge(dev) browser in inprivate mode instead of opening in normal mode.

for example, "C:\Program Files (x86)\Microsoft\Edge Dev\Application\msedge.exe" -inprivate

Any settings to set in vite.config.js file? Is there any system wide environment variable I can set?

(Found ZERO information regarding this in vite docs.)

CodePudding user response:

It used to be possible to set process.env.BROWSER, and vite would use that. For some reason, that has quit working.

I currently add it to my "dev" script in package.json

So, in vite.config.js, I set:

  server: {
    ...
    open: true,
  }

Then, in package.json, I set:

  scripts: {
    ...
    "dev": "open -a 'Google Chrome' && vite"
  }

This opens Chrome (my preferred dev browser), then opens the project there even though Chrome is not my default browser.

A caveat here is that I'm not sure why it doesn't open it in my default browser even if Chrome is already open. Your system may behave differently.

This is on Mac. For Windows and Linux, you'll need to use the command specific to that OS, and you probably have more understanding of that than I do.

I actually wound up here hoping someone had come up with a better solution for this, but I don't see anything else, so I figured I'd share my bit of kludge.

CodePudding user response:

At the time of writing, Vite doesn't support passing argument in server.open in vite.config.js file - see Vite Issue 9557

So, at the moment, editing package.json is the only solution - the following works


//both of the default script-shell and shell is set to powershell

"scripts": 
{
    "dev": "& 'C:\\Program Files (x86)\\Microsoft\\Edge Dev\\Application\\msedge.exe' --inprivate 127.0.0.1:5173  && vite"
}
  • Related