插件 SDK 参考
🌐 Plugin SDK reference
插件 SDK 是由包提供的一组命令 @strapi/sdk-plugin ,围绕开发插件,以便将它们作为本地插件使用,或发布到 NPM 和/或提交到市场。
🌐 The Plugin SDK is set of commands provided by the package @strapi/sdk-plugin orientated around developing plugins to use them as local plugins or to publish them on NPM and/or submit them to the Marketplace.
本文件列出了可用的插件 SDK 命令。相关指南说明了如何使用这些命令从头创建插件,将其链接到现有项目,并发布它。
🌐 The present documentation lists the available Plugin SDK commands. The associated guide illustrates how to use these commands to create a plugin from scratch, link it to an existing project, and publish it.
npx @strapi/sdk-plugin init
在给定路径创建一个新插件。
🌐 Create a new plugin at a given path.
npx @strapi/sdk-plugin init
| 参数 | 类型 | 描述 | 默认值 || --- | :----: | --- | --- || path | 字符串 | 插件的路径 | ./src/plugins/my-plugin |
| 选项 | 类型 | 描述 | 默认值 || --- | :--: | --- | --- || -d, --debug | - | 启用调试模式并输出详细日志 | false || --silent | - | 不记录任何日志 | false |
strapi 插件 构建
🌐 strapi-plugin build
打包 Strapi 插件以进行发布。
🌐 Bundle the Strapi plugin for publishing.
strapi-plugin build
| 选项 | 类型 | 描述 | 默认值 || --- | :----: | --- | --- || --force | 字符串 | 自动对所有提示回答“是”,包括可能具有破坏性的请求,并以非交互方式运行。 | - || -d, --debug | - | 启用调试模式并显示详细日志 | false || --silent | - | 不记录任何日志 | false || --minify | - | 压缩输出 | false || --sourcemap | - | 生成源映射 | false |
从 v6 开始,构建配置会自动从你的 package.json exports 字段中派生。不需要任何配置文件(例如 vite.config.ts 或 rollup.config.ts)。
🌐 As of v6, the build configuration is automatically derived from your package.json exports field. No configuration file (such as vite.config.ts or rollup.config.ts) is needed.
如果你需要继续使用带有 @strapi/pack-up 的先前构建系统,你可以固定到 5.x 版本:
🌐 If you need to continue using the previous build system with @strapi/pack-up, you can pin to version 5.x:
- Yarn
- NPM
yarn add @strapi/sdk-plugin@5
npm install @strapi/sdk-plugin@5
SDK 插件的 5.x 版本支持用于自定义构建配置的 packup.config.ts。然而,推荐使用 v6 以获得安全更新和简化的配置。
🌐 Version 5.x of the SDK plugin supports packup.config.ts for custom build configuration. However, v6 is recommended for security updates and simplified configuration.
strapi 插件 watch:link
🌐 strapi-plugin watch:link
在插件发生更改时自动重新编译插件并运行 yalc push --publish。
🌐 Recompiles the plugin automatically on changes and runs yalc push --publish.
为了测试目的,将你的插件链接到现有应用以在真实 条件下进行实验是非常方便的。此命令旨在帮助你简化此过程。
🌐 For testing purposes, it is very convenient to link your plugin to an existing application to experiment with it in real condition. This command is made to help you streamline this process.
strapi-plugin watch:link
| 选项 | 类型 | 描述 | 默认值 || --- | :--: | --- | --- || -d, --debug | - | 启用调试模式并输出详细日志 | false || --silent | - | 不记录任何日志 | false |
strapi 插件 监视
🌐 strapi-plugin watch
监视插件源代码的任何更改并每次重建它。在实现插件并在应用中测试时非常有用。
🌐 Watch the plugin source code for any change and rebuild it everytime. Useful when implementing your plugin and testing it in an application.
strapi-plugin watch
| 选项 | 类型 | 描述 | 默认值 || --- | :--: | --- | --- || -d, --debug | - | 启用调试模式并输出详细日志 | false || --silent | - | 不记录任何日志 | false |
strapi 插件验证
🌐 strapi-plugin verify
在发布插件之前验证插件的输出。
🌐 Verify the output of the plugin before publishing it.
strapi-plugin verify
| 选项 | 类型 | 描述 | 默认值 || --- | :--: | --- | --- || -d, --debug | - | 启用调试模式并输出详细日志 | false || --silent | - | 不记录任何日志 | false |