1、安装Chocolatey
(1)以管理员身份运行PowerShell
(2)设置Chocolatey安装位置
$env:ChocolateyInstall='E:\Program_Files\Chocolatey'
(3)安装Chocolatey
[Environment]::SetEnvironmentVariable('ChocolateyInstall',$env:ChocolateyInstall,'Machine') Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
2、安装mkcert
choco install mkcert
3、生成https证书
(1)新建文件夹来存放证书(这步可不做,但是生成的证书会在c盘中)
cd D:/证书
(2)执行命令生成证书
mkcert localhost 127.0.0.1
4、Vite配置https证书
server: { host: true, port: 8886, cors: true, open: true, https: { key: fs.readFileSync("keys/localhost+1-key.pem"), // 读取我们上面生成的公钥 cert: fs.readFileSync("keys/localhost+1.pem"), // 读取我们上面生成的证书 }, proxy: {}, },