开发证书插件
插件包 | @rushstack/heft-dev-cert-plugin |
插件名称 | trust-dev-certificate-plugin 由 TrustDevCertificatePlugin.ts 实现 untrust-dev-certificate-plugin 由 UntrustDevCertificatePlugin.ts 实现 |
插件配置文件 | (无) |
heft.json 选项 | (无) |
这是一个 Heft 插件,用于管理 https://localhost
开发服务器的自签名 SSL 证书。
基础功能由 @rushstack/debug-certificate-manager 库提供,该库提供了生成、自签名、信任和不信任 Windows 和 Mac OS 的 .pem 证书的功能。
何时使用它
通常,http://localhost
对于本地开发来说效果很好,但是如果您的应用程序需要向其 CORS 策略需要 SSL 的生产服务发出请求,则可能需要 HTTPS。在这种情况下,您的 webpack-dev-server
或 Node.js 服务将需要配置自签名证书。此插件会自动生成证书、安装它并配置您的操作系统以信任它。
package.json 依赖项
- Rush
- NPM
# If you are using Rush, run this shell command in your project folder:
rush add --package @rushstack/heft-dev-cert-plugin --dev
# If you are using vanilla NPM, run this shell command in your project folder:
npm install @rushstack/heft-dev-cert-plugin --save-dev
配置
trust-dev-certificate-plugin
可以使用类似以下的配置映射到 heft trust-dev-cert
和 heft untrust-dev-cert
操作
<项目文件夹>/config/heft.json
{
"$schema": "https://developer.microsoft.com/json-schemas/heft/v0/heft.schema.json",
"phasesByName": {
"trust-dev-cert": {
"tasksByName": {
"trust-dev-cert": {
"taskPlugin": {
"pluginPackage": "@rushstack/heft-dev-cert-plugin",
"pluginName": "trust-dev-certificate-plugin"
}
}
}
},
"untrust-dev-cert": {
"tasksByName": {
"untrust-dev-cert": {
"taskPlugin": {
"pluginPackage": "@rushstack/heft-dev-cert-plugin",
"pluginName": "untrust-dev-certificate-plugin"
}
}
}
}
}
}