1. 使用 mkcert 建立憑證
$ brew install mkcert $ mkcert -install Created a new local CA $ mkcert example.com "*.example.com" example.test localhost 127.0.0.1 ::1 Using the local CA Created a new certificate valid for the following names 📜 - "example.com" - "*.example.com" - "example.test" - "localhost" - "127.0.0.1" - "::1" The certificate is at "./example.com+5.pem" and the key at "./example.com+5-key.pem" ✅
2. 將憑證放入專案資料夾,並在 vue.config.js
加入:
const fs = require('fs') module.exports = { devServer: { https: { key: fs.readFileSync('./certs/example.com+5-key.pem'), cert: fs.readFileSync('./certs/example.com+5.pem'), }, public: 'https://localhost:8080/' } }