需要开发一个插件来实现一些自定义功能,官方文档写的实在是难以理解了。
1. 创建基础的目录结构
# 作为项目根目录
mkdir xxx
# 进入项目目录
cd xxx
# 创建strapi 项目
npx create-strapi@latest strapi
# 创建插件
npx @strapi/sdk-plugin init strapi-plugin
2. 配置工作区
# xxx目录中添加workspace配置
{
"workspaces": [
"strapi",
"strapi-plugin"
],
"dependencies": [
"strapi-plugin": "workspace:*"
]
}
3. strapi目录引入依赖
{
...
"dependencies": {
...
"strapi-plugin": "0.0.0"
}
}
4. 插件目录监听文件修改
# 根目录执行
npm run watch --workspace=strapi-plugin
5. 运行strapi
npm run develop --workspace=strapi