v4 代码迁移:更新依赖
¥v4 code migration: Updating dependencies
本指南是 v4 代码迁移指南 的一部分,旨在帮助你将 Strapi 应用的代码从 v3.6.x 迁移到 v4.0.x
¥This guide is part of the v4 code migration guide designed to help you migrate the code of a Strapi application from v3.6.x to v4.0.x
在 Strapi v3 中,Strapi 软件包名称以 strapi-
为前缀。
¥In Strapi v3, Strapi package names were prefixed with strapi-
.
Strapi v4 使用范围包,前缀为 @strapi/
。
¥Strapi v4 uses scoped packages, prefixed with @strapi/
.
在 Strapi v4 中,许多包不再需要在 package.json
中手动定义。
¥In Strapi v4, many packages no longer need to be defined manually in the package.json
.
以下示例显示了 Strapi v3 package.json
和 Strapi v4 package.json
的比较。@strapi/
前缀范围内的所有 Strapi 软件包版本应该是相同的版本。
¥The following examples show a comparison of a Strapi v3 package.json
and a Strapi v4 package.json
. All Strapi package versions from the @strapi/
prefix scope should be the same version.
Example of a Strapi v3 package.json file:
{
"name": "strapi-v3-project",
"private": true,
"version": "0.1.0",
"description": "A Strapi application",
"scripts": {
"develop": "strapi develop",
"start": "strapi start",
"build": "strapi build",
"strapi": "strapi"
},
"devDependencies": {},
"dependencies": {
"strapi": "3.6.9",
"strapi-admin": "3.6.9",
"strapi-utils": "3.6.9",
"strapi-plugin-content-type-builder": "3.6.9",
"strapi-plugin-content-manager": "3.6.9",
"strapi-plugin-users-permissions": "3.6.9",
"strapi-plugin-email": "3.6.9",
"strapi-plugin-upload": "3.6.9",
"strapi-plugin-i18n": "3.6.9",
"strapi-connector-bookshelf": "3.6.9",
"knex": "0.21.18",
"sqlite3": "5.0.0"
},
"author": {
"name": "A Strapi developer"
},
"strapi": {
"uuid": "64f95072-c082-4da8-be68-6d483781cf54"
},
"engines": {
"node": ">=10.16.0 <=14.x.x",
"npm": "^6.0.0"
},
"license": "MIT"
}
Example of a Strapi v4 package.json file:
{
"name": "strapi-v4-project",
"private": true,
"version": "0.1.0",
"description": "A Strapi application",
"scripts": {
"develop": "strapi develop",
"start": "strapi start",
"build": "strapi build",
"strapi": "strapi"
},
"devDependencies": {},
"dependencies": {
"@strapi/strapi": "4.1.2",
"@strapi/plugin-users-permissions": "4.1.2", // Optional Package
"@strapi/plugin-i18n": "4.1.2", // Optional Package
"sqlite3": "5.0.2"
},
"author": {
"name": "A Strapi developer"
},
"strapi": {
"uuid": "b8aa7baf-d6dc-4c50-93d4-7739bc88c3fd"
},
"engines": {
"node": ">=16.x.x <=20.x.x",
"npm": ">=6.0.0"
},
"license": "MIT"
}
下表重点介绍了新的和已删除的软件包:
¥The following table highlights new and removed packages:
名称前带有 ❗ 表情符号的包是必需的,并且需要在
package.json
文件中定义。¥Packages with a ❗ emoji before their name are required and need to be defined in the
package.json
file.名称前带有 🔌 表情符号的软件包是可选插件/提供程序,可以根据需要安装或删除。
¥Packages with a 🔌 emoji before their name are optional plugins/providers that can be installed or removed as needed.
名称前带有 ✨ 表情符号的软件包在 Strapi v4 中具有新名称,但不需要在
package.json
中定义。¥Packages with a ✨ emoji before their name have a new name in Strapi v4 but do not need to be defined in your
package.json
.用 ❌ 表情符号标识的包已从 Strapi v4 中删除,并且应从代码中删除对这些包的所有引用。
¥Packages identified with the ❌ emoji have been removed from Strapi v4 and all references to these packages should be removed from the code.
Strapi v3 中的软件包名称 | Strapi v4 中的软件包名称 |
---|---|
strapi | ❗ @strapi/strapi |
strapi-database | ✨ @strapi/database |
strapi-admin | ✨ @strapi/admin |
strapi-utils | ✨ @strapi/utils |
strapi-helper-plugin | ✨ @strapi/helper-plugin |
strapi-plugin-users-permissions | 🔌 @strapi/plugin-users-permissions |
strapi-plugin-i18n | 🔌 @strapi/plugin-i18n |
strapi-plugin-upload | ✨ @strapi/plugin-upload |
strapi-plugin-documentation | 🔌 @strapi/plugin-documentation |
strapi-plugin-graphql | 🔌 @strapi/plugin-graphql |
strapi-plugin-email | ✨ @strapi/plugin-email |
strapi-plugin-sentry | 🔌 @strapi/plugin-sentry |
strapi-plugin-content-type-builder | ✨ @strapi/plugin-content-type-builder |
strapi-plugin-content-manager | ✨ @strapi/plugin-content-manager |
strapi-provider-upload-local | ✨ @strapi/provider-upload-local |
strapi-provider-upload-aws-s3 | 🔌 @strapi/provider-upload-aws-s3 |
strapi-provider-upload-cloudinary | 🔌 @strapi/provider-upload-cloudinary |
strapi-provider-email-sendmail | ✨ @strapi/provider-email-sendmail |
strapi-provider-email-amazon-ses | 🔌 @strapi/provider-email-amazon-ses |
strapi-provider-email-mailgun | 🔌 @strapi/provider-email-mailgun |
strapi-provider-email-nodemailer | 🔌 @strapi/provider-email-nodemailer |
strapi-provider-email-sendgrid | 🔌 @strapi/provider-email-sendgrid |
创建 Strapi 启动器 | 创建 Strapi 启动器 |
创建 Strapi 应用 | 创建 Strapi 应用 |
strapi-generate-policy | strapi-generate-policy |
strapi-generate-controller | strapi-generate-model |
strapi-generate-model | strapi-generate-controller |
strapi-generate-new | strapi-generate-new |
strapi-generate | strapi-generate |
strapi-generate-api | strapi-generate-api |
strapi-generate-plugin | strapi-generate-plugin |
strapi-generate-service | strapi-generate-service |
strapi-provider-upload-rackspace | ❌ (从 v4 中删除) |
strapi-connector-mongoose | ❌ (从 v4 中删除) |
strapi-connector-bookshelf | ❌ (从 v4 中删除) |
strapi-hook-redis | ❌ (从 v4 中删除) |
strapi-hook-ejs | ❌ (从 v4 中删除) |
strapi-middleware-views | ❌ (从 v4 中删除) |
Example of updating a dependency to Strapi v4:
如果 Strapi v3 应用的 package.json
文件具有 “strapi-plugin-users-permissions”: “3.6.x”
依赖声明,并且迁移目标为 Strapi v4.1.2,则应将依赖声明替换为 “@strapi/plugin-users-permissions”: “4.1.2”
。
¥If the package.json
file of a Strapi v3 application has the “strapi-plugin-users-permissions”: “3.6.x”
dependency declaration, and the migration targets Strapi v4.1.2, the dependency declaration should be replaced with “@strapi/plugin-users-permissions”: “4.1.2”
.
Strapi 的 迁移后端代码 到 v4 还需要至少迁移 Strapi 服务器的核心功能,例如 configuration、routes、controllers、services 和 内容类型模式。
¥Migrating the backend code of Strapi to v4 also requires to at least migrate the core features of the Strapi server, such as the configuration, routes, controllers, services, and content-type schemas.