Artwork by Riot Games
vite-plugin-https-certs
Vite plugin to find certificate/key files and override server.https config before resolution.
❓ Why would I need this?
This plugin comes in handy when you need your dev server to serve over HTTPS without being annoyed by insecure browser warnings but avoid sharing certificates:
- Generate a self signed certificate and a matching key for localhost (example).
- Trust the certificate (
keychain
,certmgr
...). - Drop the certificate in configured project folder (
.certs
by default). - Add the plugin to your Vite config.
- Add the folder to your
.gitignore
, the idea is that everyone uses their own certificate.
By default, if the plugin is in your Vite config, your server will still be served over HTTPS but without certificates.
✨ Features
- Automatically find certificate and key from folder.
- Overrides
server.https
config before resolution. - Default 'no-config' values.
- Fallback to
true
orfalse
(configurable). - Custom extensions.
🚀 Usage
Default
When no config is passed, the plugin will look in .certs
folder for:
- a key with
.key
extension. - a certificate with
.cer
or.cert
extension.
If one is missing, server.https
will be set to true
.
import { defineConfig } from 'vite'
import HttpsCerts from 'vite-plugin-https-certs'
export default defineConfig({
plugins: [
// ....
HttpsCert(),
//...
]
})
Available options
You can provide options to configure the plugin:
-
path
: overrides the path to the certificate containing folder. -
certExts
: overrides the accepted certificate file extensions. -
keyExts
: overrides the accepted key file extensions. -
defaultIfNoCerts
: overrides the valueserver.https
should be set to when no certificate is found.
import { defineConfig } from 'vite'
import HttpsCerts from 'vite-plugin-https-certs'
export default defineConfig({
plugins: [
// ....
HttpsCert({
path: '.certs',
certExts: ['.cert', '.cer'],
keyExts: ['.key'],
defaultIfNoCerts; false,
}),
//...
]
})
🚧 Caveats
This plugin only overrides the config before its resolution by Vite. Certificate and key validations are still done during the dev server creation. The certificate and key fetching is done by checking the file extensions.
If the given certificate and keys are invalid, the dev server will not start.
Certificate validation at config step might come in a future update.
🤝 Contributing
Any contribution to the project is welome.
Run into a problem? Open an issue.
Want to add some feature? PRs are welcome!
👤 About the author
Feel free to contact me:
📝 Licence
Copyright © 2021 Sacha Bouillez.
This project is under MIT license.