Skip to content

生成本地开发证书

生成证书

全局安装:npm install -g mkcert

创建ca证书颁发机构:mkcert create-ca

双击生成的ca.crt,受信任的根证书颁发机构

创建本地证书:mkcert create-cert --validity 3650 "*.Domain.com"

https://www.npmjs.com/package/mkcert

vue-cli项目配置

js
import fs from 'fs'

module.exports = {
  devServer: {
    https: {
      key: fs.readFileSync('path/to/privatekey.key'),
      cert: fs.readFileSync('path/to/certificate.crt'),
    }
  }
}

vite项目配置

js
import fs from 'fs'

export default {
  server: {
    https: {
      key: fs.readFileSync('/path/to/your/privatekey.key'),
      cert: fs.readFileSync('/path/to/your/certificate.crt')
    }
  }
}