Setup Vue.js with Https Certificate

Prerequisites

VS Code v1.39.1
Vue v3.12.0
Node v10.16.0

versions

Setup mkcert

Download mkcert from here (v1.4.0)

Set the PATH variable or copy the exe to an existing PATH folder.
Rename to mkcert.exe, so that you can run it easier. I copied mine to “D:\Installs\VSCode\Microsoft VS Code\bin”.
Check that you can run it by running mkcert –help.

mkcert

Create the root CA by running

mkcert –install

Say yes to the prompt and 2 files will be created at the location specified.

rootCA_files

Create Cert for the project

In VS Code create a folder called certs.
In cmd prompt navigate to that folder.
Run the following.

create_cert

Update vue.config.js (create it at the project root if not there) with the following.

const fs = require("fs");

module.exports = {
  devServer: {
    https: {
      key: fs.readFileSync("./certs/localhost-key.pem"),
      cert: fs.readFileSync("./certs/localhost.pem")
    }
  }
};

vscode

Run the project with npm run serve, and browse the results.

chrome1chrome2chrome3chrome4Edge1IE1

References

https://github.com/FiloSottile/mkcert

https://stackoverflow.com/questions/45807049/how-to-run-vue-js-dev-serve-with-https

https://medium.com/@aweber01/locally-trusted-development-certificates-with-mkcert-and-iis-e09410d92031

https://github.com/FiloSottile/mkcert/issues/73