配置文件的严格要求
🌐 Strict requirements for configuration files
Strapi 5 对允许加载的配置文件名有严格要求。
此页面是重大更改数据库的一部分,提供关于重大更改的信息以及从 Strapi v4 迁移到 Strapi 5 的附加说明。
🌐 This page is part of the breaking changes database and provides information about the breaking change and additional instructions to migrate from Strapi v4 to Strapi 5.
重大变更描述
🌐 Breaking change description
在 Strapi v4 中
Strapi 项目的 /config/ 文件夹中的每个 .js、.ts 和 .json 文件都会被加载到 strapi.config 中。
🌐 Every .js, .ts, and .json file in the /config/ folder of a Strapi project is loaded into strapi.config.
例如,如果有一个名为 /config/my-custom-config.js 的文件,它会被加载并且可以从 strapi.config.get('my-custom-config.someProperty') 访问。
🌐 For example if there is a file called /config/my-custom-config.js it is loaded and accessible from strapi.config.get('my-custom-config.someProperty').
在 Strapi 5 中
Strapi 5 对允许加载的文件名有严格的要求(有关详细信息,请参阅注释)。
🌐 Strapi 5 has strict requirements on the filenames allowed to be loaded (see notes for details).
迁移
🌐 Migration
本节重新组合了有关引入的重大更改的有用说明和程序。
🌐 This section regroups useful notes and procedures about the introduced breaking change.
注意
🌐 Notes
在 Strapi 5 中,配置文件的文件名应符合以下要求:
🌐 In Strapi 5 filenames for configuration files should comply to these requirements:
- 不应存在不区分大小写的重复文件名。如果
CUSTOM.js和custom.js都存在,只会加载其中一个。 - 不应存在没有扩展名的重复基本文件名。如果
custom.json和custom.js都存在,只会加载其中一个。 - 以下文件名受到限制且未加载:
uuidhostinglicenseenforcedisableenablepluginstrapimiddlewaretelemetrylaunchedAtserveAdminPanelautoReloadenvironmentpackageJsonStrapiinfoautoReload
- 建议只使用字母数字字符(
a-zA-Z0-9)。 - 所有内部 Strapi 配置(参见 configurations 中的文件列表)必须符合这些配置文件的已知结构(即,不应在现有文件中添加自定义字段)。
手动迁移
🌐 Manual migration
在迁移之前重命名任何属于限制列表的自定义字段或内容类型,以防止数据丢失或其他意外问题。
🌐 Rename any of configuration files that are now invalid to a new name, and update the code to look in that path.
如果你在内部 Strapi 配置文件中添加了自定义字段,则应该创建一个新文件来存储自定义配置,并确保新文件名符合 Strapi 5 的要求。
🌐 If you added custom fields to the internal Strapi configuration files, you should instead create a new file to store the custom configuration, and ensure the new filename matches the requirements for Strapi 5.