prazdevs / vite-plugin-https-certs

πŸ” Vite plugin to find certificate/key files and override server.https config before resolution.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This repo/package is not maintained anymore. vite-plugin-mkcert does a much better job :)


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.

About

πŸ” Vite plugin to find certificate/key files and override server.https config before resolution.

License:MIT License


Languages

Language:TypeScript 100.0%