What is vite-plugin-mkcert?
vite-plugin-mkcert is a Vite plugin that allows you to easily create and use locally-trusted development certificates. This is particularly useful for developing applications that require HTTPS in a local environment.
What are vite-plugin-mkcert's main functionalities?
Automatic Certificate Generation
This feature automatically generates and uses locally-trusted development certificates, making it easy to set up HTTPS for your local development environment.
import mkcert from 'vite-plugin-mkcert';
export default {
plugins: [mkcert()]
};
Custom Certificate Options
This feature allows you to specify custom certificate and key paths, giving you more control over the certificates used in your local development environment.
import mkcert from 'vite-plugin-mkcert';
export default {
plugins: [
mkcert({
source: 'path/to/custom/certificates',
key: 'path/to/custom/key.pem',
cert: 'path/to/custom/cert.pem'
})
]
};
Other packages similar to vite-plugin-mkcert
webpack-dev-server
webpack-dev-server is a development server that provides live reloading and HTTPS support. It can be configured to use self-signed certificates, but it does not automatically generate locally-trusted certificates like vite-plugin-mkcert.
create-ssl-certificate
create-ssl-certificate is a package that generates self-signed SSL certificates for local development. Unlike vite-plugin-mkcert, it does not integrate directly with Vite and requires manual setup.
devcert
devcert is a library for generating locally-trusted development certificates. It provides similar functionality to vite-plugin-mkcert but is not specifically designed for Vite and requires additional configuration.
vite-plugin-mkcert
Use mkcert to provide certificate support for vite https development services.
When should I use this plugin
- 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.
Effect
View
Quick start
- Installation dependencies
yarn add vite-plugin-mkcert -D
- Configure vite
import {defineConfig} from'vite'
import mkcert from'vite-plugin-mkcert'
export default defineConfig({
server: {
https: true
},
plugins: [mkcert()]
})
Parameters
force
Whether to force generate.
autoUpgrade
Whether to automatically upgrade mkcert
.
source
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.
mkcertPath
If the network is restricted, you can specify a local mkcert
file instead of downloading from the network.
hosts
Custom hosts, default value is localhost
+ local ip addrs
.
Display the debugging information of the plug-in
Set the environment variable DEBUG
=vite:plugin:mkcert
CHANGELOG
CHANGELOG
Principle
Use mkcert to install the local CA
certificate and generate it for server.https Server certificate.
Friendly reminder
mkcert
save directory: PLUGIN_DATA_DIR- Uninstall the
CA
certificate: mkcert uninstall
Thanks