--- title: HTTPS with the Vite development server description: How to enable HTTPS on a local Vite development server. url: https://mattrossman.com/2024/03/15/https-with-the-vite-development-server/ image: https://mattrossman.com/open-graph/2024/03/15/https-with-the-vite-development-server.png --- # HTTPS with the Vite development server Mar 15, 2024 Enabling HTTPS with Vite’s dev server used to be as simple as running: ``` vite --https ``` This was refreshingly simple in a ecosystem where most build tool dev servers use plain HTTP, and enabling HTTPS is either unsupported or requires several arcane steps. In recent versions of Vite you may notice that the `--https` flag alone isn’t enough anymore. ![Error saying "This site can’t provide a secure connection"](https://mattrossman.com/_astro/error.df4lLYu5_Z1KtIXP.webp) There’s one more step to recreate the old behavior, which is to add the [@vitejs/plugin-basic-ssl](https://www.npmjs.com/package/@vitejs/plugin-basic-ssl) plugin to the Vite config. ``` // vite.config.js import { defineConfig } from "vite" import basicSsl from "@vitejs/plugin-basic-ssl" export default defineConfig({ plugins: [basicSsl()], }) ``` Although they recommend generating a secure trusted certificate, I don’t see a reason to make it any more complicated than this for local development. Usually the reason I need HTTPS is because I’m testing a WebXR experience (which requires a secure context) from another device on my network (which rules out localhost). Thus, I’m almost always using HTTPS in combination with Vite’s `--host` option to expose the server to my LAN. Here’s a more complete config that includes all these options when running `vite`. ``` // vite.config.js import { defineConfig } from "vite" import basicSsl from "@vitejs/plugin-basic-ssl" export default defineConfig({ plugins: [basicSsl()], server: { https: true, // same as "--https" flag host: true, // same as "--host" flag }, }) ```