Skip to main content

特性配置

¥Features configuration

config/features.js|ts 文件用于启用功能标志。目前,此文件仅包含 future 对象,用于通过未来标志启用实验功能。

¥The config/features.js|ts file is used to enable feature flags. Currently this file only includes a future object used to enable experimental features through future flags.

一些即将推出的 Strapi 功能尚未准备好交付给所有用户,但 Strapi 仍然为社区用户提供对这些新功能或更改提供早期反馈的机会。借助这些实验性功能,开发者可以灵活地选择新功能和更改并将其集成到他们的 Strapi 应用中(当它们在当前主要版本中可用时),并协助我们塑造这些新功能。

¥Some incoming Strapi features are not yet ready to be shipped to all users, but Strapi still offers community users the opportunity to provide early feedback on these new features or changes. With these experimental features, developers have the flexibility to choose and integrate new features and changes into their Strapi applications as they become available in the current major version as well as assist us in shaping these new features.

此类实验性功能在整个文档中由 Future 徽章表示,并且启用这些功能需要启用相应的未来标志。未来标志与 alpha 版本的功能不同,未来标志默认处于禁用状态。

¥Such experimental features are indicated by a Future badge throughout the documentation and enabling these features requires enabling the corresponding future flags. Future flags differ from features that are in alpha in that future flags are disabled by default.

❗️ 危险

启用未来标志的风险由你自行承担。实验功能可能会发生更改或删除,可能包含重大更改,可能不稳定或未完全准备好使用,并且某些部分可能仍在开发或使用模拟数据。

¥Enable future flags at your own risk. Experimental features may be subject to change or removal, may contain breaking changes, may be unstable or not fully ready for use, and some parts may still be under development or using mock data.

启用未来标志

¥Enabling a future flag

要启用未来标志:

¥To enable a future flag:

  1. (可选)如果服务器正在运行,请使用 Ctrl-C 停止它。

    ¥(optional) If the server is running, stop it with Ctrl-C.

  2. 打开 config/features.js|ts 文件,如果该文件尚不存在,则创建它。该文件将导出一个 future 对象,其中包含所有要启用的未来标志。

    ¥Open the config/features.js|ts file or create it if the file does not exist yet. The file will export a future object with all the future flags to enable.

  3. 要启用未来标志,请将其属性名称(请参阅 完整列表)添加到 future 对象,并确保该属性的值设置为 true。以下示例显示如何启用 contentReleasesScheduling 未来标志:

    ¥To enable a future flag, add its property name (see full list) to the future object and ensure the property's value is set to true. The following example shows how to enable the contentReleasesScheduling future flag:

/config/features.ts
module.export = ({ env }) => ({
future: {
// You could also simply write: contentReleases: true
contentReleasesScheduling: env.bool('STRAPI_FUTURE_CONTENT_RELEASES_SCHEDULING', false),
},
})

此示例假设你的应用根目录下有一个 .env 环境文件,并且该文件包含以下行:

¥This example assumes that you have an .env environment file at the root of your application and that the file includes the following line:

.env
STRAPI_FUTURE_CONTENT_RELEASES_SCHEDULING=true

如果你的环境文件不包含此值,则 contentReleasesScheduling 未来标志属性值将默认为 false,并且实验功能将不会启用。

¥If your environment file does not include this value, the contentReleasesScheduling future flag property value will default to false and the experimental feature will not be enabled.

  1. 重建管理面板并重新启动服务器:

    ¥Rebuild the admin panel and restart the server:

```sh
yarn develop
```

未来标志 API

¥Future flags API

开发者可以使用以下 API 与未来的标志进行交互:

¥Developers can use the following APIs to interact with future flags:

  • 功能配置是 config 对象的一部分,可以使用 strapi.config.get('features')strapi.features.config 读取。

    ¥Features configuration is part of the config object and can be read with strapi.config.get('features') or with strapi.features.config.

  • strapi.features.future 返回 isEnabled(),可用于确定是否启用未来标志,使用以下方法:strapi.features.future.isEnabled('featureName')

    ¥strapi.features.future returns the isEnabled() that can be used to determine if a future flag is enabled, using the following method: strapi.features.future.isEnabled('featureName').

可用的未来标志

¥Available future flags

目前没有可用的未来标志。一旦新的实验功能可供测试,本节将进行更新。

¥There are currently no available future flags. This section will be updated once new experimental features are available for testing.