This package has been deprecated

Author message:

use vite-plugin-mkcert instead

vite-plugin-https-certs
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

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:

  1. Generate a self signed certificate and a matching key for localhost (example).
  2. Trust the certificate (keychain, certmgr...).
  3. Drop the certificate in configured project folder (.certs by default).
  4. Add the plugin to your Vite config.
  5. 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 or false (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 value server.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!

Open in Visual Studio Code

👤 About the author

Feel free to contact me:

📝 Licence

Copyright © 2021 Sacha Bouillez.
This project is under MIT license.

Versions

Current Tags

VersionDownloads (Last 7 Days)Published

Version History

VersionDownloads (Last 7 Days)Published

Package Sidebar

Install

npm i vite-plugin-https-certs

Weekly Downloads

67

Version

1.1.1

License

MIT

Unpacked Size

10.6 kB

Total Files

6

Last publish

Collaborators

  • prazdevs