1. 安装scoop
管理员权限打开PowerShell输入如下
set-executionpolicy remotesigned -s cu
iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
2. 安装mkcert
scoop bucket add extras
scoop install mkcert
3. 生成localhost证书
mkcert -install
mkcert example.com "*.example.org" myapp.dev localhost 127.0.0.1 ::1
当前目录下会有如下文件
example.com+5.pem
example.com+5-key.pem
4. 本地服务器配置证书
假设你使用vue-cli3,对vue.config.js
进行配置。
https: {
key: fs.readFileSync( '路径/localhost-key.pem'),
cert: fs.readFileSync( '路径/localhost.pem'),
},
打开新标签或者重启浏览器即可。

参考
https://github.com/lukesampson/scoop
https://github.com/FiloSottile/mkcert
网友评论