開發證書外掛模組
外掛模組套件 | @rushstack/heft-dev-cert-plugin |
外掛模組名稱 | trust-dev-certificate-plugin 由 TrustDevCertificatePlugin.ts 實作 untrust-dev-certificate-plugin 由 UntrustDevCertificatePlugin.ts 實作 |
外掛模組設定檔 | (無) |
heft.json 選項 | (無) |
這是 Heft 外掛模組,可管理 https://127.0.0.1
開發伺服器的自簽署 SSL 憑證。
基礎功能由 @rushstack/debug-certificate-manager 函式庫提供,它提供可在 Windows 和 Mac OS 上為 .pem 憑證產生、自簽、信任和不信任功能。
何時使用
通常 https://127.0.0.1
能正常地進行在地端開發,但如果 app 需要向實際環境服務發出請求,而且其 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"
}
}
}
}
}
}