使用 Rush 外掛程式 (實驗性質)
Rush 外掛程式可讓您
- 在多個單一儲存庫之間共用常見的 Rush 設定
- 使用自訂功能擴充 Rush 的基本功能
- 在正式將新的功能概念貢獻給 Rush 之前,先進行原型設計
外掛程式是透過 NPM 套件散佈,我們稱之為外掛程式套件。單一套件可以定義一個或多個 Rush 外掛程式。(如果您有興趣建立自己的外掛程式套件,請參閱文章建立 Rush 外掛程式。)
啟用 Rush 外掛程式
在您的單一儲存庫中啟用 Rush 外掛程式有三個步驟。在本教學中,讓我們設定一個名為 "example"
的假設外掛程式,該外掛程式由 NPM 套件 @your-company/rush-example-plugin
提供。
步驟 1:設定自動安裝程式
外掛程式依賴 Rush 的自動安裝程式功能,以便隨選安裝其 NPM 套件。
以下是如何建立一個名為 rush-plugins
的新自動安裝程式
rush init-autoinstaller --name rush-plugins
這會建立自動安裝程式 package.json 檔案。將您外掛程式的 NPM 套件新增為相依性
common/autoinstallers/rush-plugins/package.json
{
"name": "rush-plugins",
"version": "1.0.0",
"private": true,
"dependencies": {
"@your-company/rush-example-plugin": "^1.0.0" 👈 👈 👈
}
}
接下來,產生 shrinkwrap 檔案
# Creates the shrinkwrap file common/autoinstallers/rush-plugins/pnpm-lock.yaml
rush update-autoinstaller --name rush-plugins
將這些檔案提交到 Git。
步驟 2:更新 rush-plugins.json
為了載入外掛程式,我們需要在 rush-plugins.json 中註冊它。繼續我們的範例
common/config/rush/rush-plugins.json
{
"$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush-plugins.schema.json",
"plugins": [
/**
* Each item defines a plugin to be loaded by Rush.
*/
{
/**
* The name of the NPM package that provides the plugin.
*/
"packageName": "@your-company/rush-example-plugin",
/**
* The name of the plugin. This can be found in the "pluginName"
* field of the "rush-plugin-manifest.json" file in the NPM package folder.
*/
"pluginName": "example",
/**
* The name of a Rush autoinstaller that will be used for installation, which
* can be created using "rush init-autoinstaller". Add the plugin's NPM package
* to the package.json "dependencies" of your autoinstaller, then run
* "rush update-autoinstaller".
*/
"autoinstallerName": "rush-plugins"
}
]
}
pluginName
欄位可以在外掛程式套件的 rush-plugin-manifest.json 中找到。
步驟 3:選用設定檔
有些外掛程式可以透過自己的設定檔自訂;如果是這樣,它們的 rush-plugin-manifest.json 將指定 optionsSchema
欄位。
設定檔名稱會與 pluginName
相同,例如
common/config/rush-plugins/example.json
第一方外掛程式
NPM 套件 | 描述 |
---|---|
@rushstack/rush-amazon-s3-build-cache-plugin | Amazon S3 的雲端建置快取提供者 |
@rushstack/rush-azure-storage-build-cache-plugin | Azure 儲存體的雲端建置快取提供者 |
@rushstack/rush-serve-plugin | (實驗性質) 一個 Rush 外掛程式,可連結到動作執行並執行 express 伺服器來提供專案輸出 |
注意:
@rushstack/rush-amazon-s3-build-cache-plugin
和@rushstack/rush-azure-storage-build-cache-plugin
套件目前已內建於 Rush 中並自動啟用。目前,您不應該在 rush-plugins.json 中註冊它們。這是外掛程式架構仍在實驗階段時的臨時措施。在 Rush 的下一個主要版本中,需要以標準方式設定建置快取套件。
第三方外掛程式
以下是一些社群貢獻的外掛程式展示。
NPM 套件 | 描述 |
---|---|
rush-archive-project-plugin | 封存不再維護的 Rush 專案 |
rush-github-action-build-cache-plugin | 在 Github 動作中儲存和還原建置快取 |
rush-init-project-plugin | 初始化新的 Rush 專案 |
rush-lint-staged-plugin | 將 lint-staged 與 Rush 單一儲存庫整合 |
rush-print-log-if-error-plugin | 發生錯誤時列印專案的整個記錄檔 |
rush-sort-package-json | 排序 Rush 專案的 package.json 檔案項目 |
rush-upgrade-self-plugin | 協助升級到最新版本的 Rush |
如果您為 Rush 建立了一個有趣的外掛程式,請在 GitHub 議題中告知我們。謝謝!