Sometimes, we want to run the Vue CLI dev server via HTTPS.
In this article, we’ll look at how to run the Vue CLI dev server via HTTPS.
Run Vue.js Dev Server with HTTPS
We can change the Vue dev server’s config to serve the project over HTTPS rather than HTTP.
To do that, we read the private key and certificate.
And we set the URL to serve the project on.
For instance, we can write:
const fs = require('fs')
module.exports = {
devServer: {
https: {
key: fs.readFileSync('./certs/key.pem'),
cert: fs.readFileSync('./certs/cert.pem'),
},
public: 'https://localhost:8888/'
}
}
We read in the files and set them as the properties of the https
property.
To make a certificate, we can use the mkcert
program to do it.
We can install it on Windows, Mac OS, or Linux by following the instructions on https://github.com/FiloSottile/mkcert.
Then we can create a new key and certificate by running:
mkcert -install
and:
mkcert example.com "*.example.com" example.test localhost 127.0.0.1 ::1
Then we created a certificate valid for localhost.
We just copy the files to the cert
folder and rename them to match what we have in the config.
Then we can run npm run dev
and serve the project.
Conclusion
We can change the Vue dev server’s config to serve the project over HTTPS rather than HTTP.