Use mkcert to provide certificate support for vite https development services.
- When you want to use
http/2
to solve the concurrency limit of vite http dev server requests, you find that the browser cache is invalid #2725. - I have obsessive-compulsive disorder, and I hope that the browser will not show annoying https certificate errors.
- Installation dependencies
yarn add vite-plugin-mkcert -D
- Configure vite
import {defineConfig} from'vite'
import mkcert from'vite-plugin-mkcert'
// https://vitejs.dev/config/
export default defineConfig({
server: {
https: true
}, // Not needed for Vite 5+ (simply omit this option)
plugins: [mkcert()]
})
Recent version of Nuxt.js use vite under the hood. You can still use this plugin to create a certificate but you need to manually specify the certificate for the devserver.
- Installation dependencies
yarn add vite-plugin-mkcert -D
- Configure nuxt
import mkcert from'vite-plugin-mkcert'
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
vite: {
plugins: [
mkcert({
savePath: './certs', // save the generated certificate into certs directory
force: true, // force generation of certs even without setting https property in the vite config
})
]
},
devServer: {
https: {
cert: './certs/cert.pem',
key: './certs/dev.pem'
}
}
});
Custom hosts, default value is localhost
+ local ip addrs
.
Whether to force generate.
Whether to automatically upgrade mkcert
.
Specify the download source of mkcert
, domestic users can set it to coding
to download from the coding.net mirror, or provide a custom BaseSource.
If the network is restricted, you can specify a local mkcert
file instead of downloading from the network.
The location to save the files, such as the downloaded mkcert program and the generated CA file, private key and certificate file, etc. Default value is PLUGIN_DATA_DIR
The name of private key file generated by mkcert
The name of cert file generated by mkcert
For the certificates to be trusted on mobile devices, you will have to install the root CA. It's the rootCA.pem
file in the folder printed by mkcert -CAROOT
.
On iOS, you can either use AirDrop, email the CA to yourself, or serve it from an HTTP server. After opening it, you need to install the profile in Settings > Profile Downloaded and then enable full trust in it.
For Android, you will have to install the CA and then enable user roots in the development build of your app. See this StackOverflow answer.
Set the environment variable DEBUG
=vite:plugin:mkcert
Use mkcert to install the local CA
certificate and generate it for server.https Server certificate.
- Uninstall the
CA
certificate:mkcert -uninstall