首页指南参考教程

配置 EAS 元数据

了解配置 EAS 元数据的不同方法。


EAS 元数据处于测试阶段,可能会发生重大变化。

EAS 元数据由项目根目录下的 store.config.json 文件配置。

¥EAS Metadata is configured by a store.config.json file at the root of your project.

你可以使用 eas.json metadataPath 属性配置存储配置文件的路径或名称。除了默认的 JSON 格式外,EAS 元数据还支持使用 JavaScript 文件的更多动态配置。

¥You can configure the path or name of the store config file with the eas.json metadataPath property. Besides the default JSON format, EAS Metadata also supports more dynamic config using JavaScript files.

静态存储配置

¥Static store config

EAS 元数据的默认存储配置类型是简单的 JSON 文件。下面的代码片段显示了一个示例存储配置,其中包含用英语(美国)编写的基本 App Store 信息。

¥The default store config type for EAS Metadata is a simple JSON file. The code snippet below shows an example store config with basic App Store information written in English (U.S.).

你可以在 存储配置架构.conf 中找到所有配置选项。

¥You can find all configuration options in the store config schema.

如果你安装了 VS Code Expo 工具扩展,你将获得 store.config.json 文件的自动补齐、建议和警告。

¥If you have the VS Code Expo Tools extension installed, you get auto-complete, suggestions, and warnings for store.config.json files.

store.config.json
{
  "configVersion": 0,
  "apple": {
    "info": {
      "en-US": {
        "title": "Awesome App",
        "subtitle": "Your self-made awesome app",
        "description": "The most awesome app you have ever seen",
        "keywords": ["awesome", "app"],
        "marketingUrl": "https://example.com/en/promo",
        "supportUrl": "https://example.com/en/support",
        "privacyPolicyUrl": "https://example.com/en/privacy"
      }
    }
  }
}

动态存储配置

¥Dynamic store config

有时,元数据属性可以从动态值中受益。例如,元数据版权声明应包含当前年份。这可以通过 EAS 元数据实现自动化。

¥At times, Metadata properties can benefit from dynamic values. For example, the Metadata copyright notice should contain the current year. This can be automated with EAS Metadata.

要动态生成内容,请首先创建 JavaScript 配置文件 store.config.js。然后,使用 eas.json 文件中的 metadataPath 属性来选择 JS 配置文件。

¥To generate content dynamically, start by creating a JavaScript config file store.config.js. Then, use the metadataPath property in the eas.json file to pick the JS config file.

eas metadata:pull 无法更新动态存储配置文件。相反,它会创建一个与配置文件同名的 JSON 文件。你可以导入 JSON 文件以重用 eas metadata:pull 中的数据。

¥eas metadata:pull can't update dynamic store config files. Instead, it creates a JSON file with the same name as the configured file. You can import the JSON file to reuse the data from eas metadata:pull.

store.config.js
// Use the data from `eas metadata:pull`
const config = require('./store.config.json');

const year = new Date().getFullYear();
config.apple.copyright = `${year} Acme, Inc.`;

module.exports = config;
eas.json
{
  "submit": {
    "production": {
      "ios": {
        "metadataPath": "./store.config.js"
      }
    }
  }
}

使用外部内容存储配置

¥Store config with external content

使用外部服务进行本地化时,你必须获取外部内容。EAS 元数据支持从动态存储配置文件导出的同步和异步函数。在验证并与商店同步之前等待函数结果。

¥When using external services for localizations, you have to fetch external content. EAS Metadata supports synchronous and asynchronous functions exported from dynamic store config files. The function results are awaited before validating and syncing with the stores.

store.config.js 函数在 Node.js 中进行评估。如果你需要特殊值(例如秘密),请使用环境变量。

¥The store.config.js function is evaluated in Node.js. If you need special values, like secrets, use environment variables.

store.config.js
// Use the data from `eas metadata:pull`
const config = require('./store.config.json');

module.exports = async () => {
  const year = new Date().getFullYear();
  const info = await fetchLocalizations('...').then(response => response.json());

  config.apple.copyright = `${year} Acme, Inc.`;
  config.apple.info = info;

  return config;
};
eas.json
{
  "submit": {
    "production": {
      "ios": {
        "metadataPath": "./store.config.js"
      }
    }
  }
}
Expo 中文网 - 粤ICP备13048890号