使用 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 问题中告诉我们。谢谢!