Open arlyxiao opened 1 year ago
brew install mkcert
brew install nss
mkcert -install
mkdir -p .cert && mkcert -key-file ./.cert/key.pem -cert-file ./.cert/cert.pem 'localhost'
import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import fs from 'fs'; // https://vitejs.dev/config/ export default defineConfig({ server: { https: { key: fs.readFileSync('./.cert/key.pem'), cert: fs.readFileSync('./.cert/cert.pem'), }, }, plugins: [react()], });
https://stackoverflow.com/questions/69417788/vite-https-on-localhost
Step: 1
Install mkcert tool - macOS; you can see the mkcert repo for details
brew install mkcert
Step: 2
Install nss (only needed if you use Firefox)
brew install nss
Step: 3
Setup mkcert on your machine (creates a CA)
mkcert -install
Step: 4 (Final)
at the project root directory run the following command
mkdir -p .cert && mkcert -key-file ./.cert/key.pem -cert-file ./.cert/cert.pem 'localhost'
vite.config.ts
Source from
https://stackoverflow.com/questions/69417788/vite-https-on-localhost