Skip to main content

管理面板扩展

🌐 Admin panel extension

Strapi的管理面板是一个基于React的单页应用,封装了Strapi应用的所有功能和已安装的插件。如果Strapi提供的自定义选项不足以满足你的使用需求,你将需要扩展Strapi的管理面板。

🌐 Strapi's admin panel is a React-based single-page application that encapsulates all the features and installed plugins of a Strapi application. If the customization options provided by Strapi are not enough for your use case, you will need to extend Strapi's admin panel.

扩展 Strapi 的管理面板意味着利用其 React 基础根据项目的特定需求调整和增强界面和功能,这可能意味着创建新组件或添加新类型的字段。

🌐 Extending Strapi's admin panel means leveraging its React foundation to adapt and enhance the interface and features according to the specific needs of your project, which might imply creating new components or adding new types of fields.

在 2 个用例中,你可能需要扩展管理面板:

🌐 There are 2 use cases where you might want to extend the admin panel: | 方法 | 范围 | 入口点 | 文档 ||---|---|---|---|| 本地扩展 | 一个 Strapi 项目 | /src/admin/app.(js\|ts)/src/admin/extensions/ | 管理面板自定义 || 插件扩展 | 安装了你的插件的任何项目 | [plugin-name]/admin/src/index.(js\|ts) | 管理面板 API 概览 |

  • 作为 Strapi 插件开发者,你希望开发一个 Strapi 插件,使其在每次安装到任何 Strapi 应用时都能扩展管理面板。👉 这可以通过利用 插件的管理面板 API 来实现,该 API 允许你添加导航链接和设置部分,将 React 组件注入到预定义区域,使用 Redux 管理状态,扩展内容管理器的编辑和列表视图,等等。
  • 作为一名 Strapi 开发者,你希望为一个只需要扩展 Strapi 应用特定实例的 Strapi 用户开发一个独特的解决方案。👉 这可以通过直接更新 /src/admin/app 文件来完成,该文件可以导入位于 /src/admin/extensions 中的任何文件。
Tip: Hot reloading while developing

在 Strapi 5 中,服务器默认以 watch-admin 模式运行,因此每当你更改其代码时,管理员面板会自动重新加载。这简化了管理员面板和前端插件的开发。要禁用此功能,请运行 yarn develop --no-watch-admin(参见 CLI 参考)。

🌐 In Strapi 5, the server runs in watch-admin mode by default, so the admin panel auto-reloads whenever you change its code. This simplifies admin panel and front-end plugins development. To disable this, run yarn develop --no-watch-admin (see CLI reference).

何时考虑使用插件

🌐 When to consider a plugin instead

从在 /src/admin/app 中进行直接自定义开始,是满足项目特定需求的正确默认方式。当出现以下一种或多种信号时,考虑转向基于插件的方法:

🌐 Starting with a direct customization in /src/admin/app is the right default for project-specific needs. Consider moving to a plugin-based approach when one or more of these signals appear:

  • 你正在将相同的管理员自定义重复应用到多个 Strapi 项目中。
  • 你想要对扩展进行版本控制和分发——无论是内部还是通过 Strapi Marketplace
  • 你需要更强大的自动化测试,独立于单个项目代码库。
  • 多个团队需要对同一个扩展进行共享所有权和版本管理。

有关插件开发的完整介绍,请参见 开发 Strapi 插件

🌐 For a full introduction to plugin development, see Developing Strapi plugins.

Additional resources
  • 如果你正在寻找替换默认富文本编辑器的方法,请参阅相应页面
  • 要了解插件如何与 Strapi 管理面板集成,请从 管理面板 API 概述 开始。