了解如何使用资源选择功能并验证更新是否包含所有必需的应用资源。
适用于 SDK 50 及更高版本 (expo-updates
>= 0.23.0)。
在 SDK 49 及更早版本中,Metro 打包程序中解析的所有资源都包含在每个更新中,并上传到更新服务器。SDK 50 中的实验性资源选择功能允许开发者指定仅应在更新中包含某些资源。这可以大大减少需要上传到更新服务器和从更新服务器下载的资源数量。此功能将与 EAS 更新服务器或任何符合 expo-updates
协议 的自定义服务器配合使用。
¥In SDK 49 and earlier, all assets resolved in the Metro bundler are included in every update and are uploaded to the update server. The experimental asset selection feature in SDK 50 allows the developer to specify that only certain assets should be included in updates. This can greatly reduce the number of assets that need to be uploaded to and downloaded from the updates server. This feature will work with the EAS Update server or any custom server that complies with the expo-updates
protocol.
¥Using asset selection
要使用资源选择,请在你的应用配置中包含属性 extra.updates.assetPatternsToBeBundled
。它应该定义一个或多个文件匹配模式(正则表达式)。例如,app.json 文件具有以下定义的模式:
¥To use the asset selection, include the property extra.updates.assetPatternsToBeBundled
in your app config. It should define one or more file-matching patterns (regular expressions). For example, an app.json file has the patterns defined in the following way:
"expo": {
%%placeholder-start%%... %%placeholder-end%%
"extra": {
"updates": {
"assetPatternsToBeBundled": [
"app/images/**/*.png"
]
}
}
}
添加此配置后,app/images 所有子目录中的所有 .png 文件都将包含在更新中。你还必须确保这些资源在你的 JavaScript 代码中是必需的
¥After adding this configuration all .png files in all subdirectories of app/images will be included in updates. You have to also ensure that these assets need to be required in your JavaScript code
如果应用配置中不包含 assetPatternsToBeBundled
,则打包器解析的所有资源都将包含在更新中(根据 SDK 49 及更早的行为)。
¥If assetPatternsToBeBundled
isn't included in the app config, all assets resolved by the bundler will be included in updates (as per SDK 49 and earlier behavior).
¥Verifying that an update includes all required app assets
使用资源选择时,与任何文件模式不匹配的资源将在 Metro 打包器中解析。但是,这些资源不会上传到更新服务器。你必须确保更新中未包含的资源已内置到应用的原生构建中。
¥When using the asset selection, assets that do not match any file patterns will resolve in the Metro bundler. However, these assets will not be uploaded to the updates server. You have to be certain that assets not included in updates are built into the native build of the app.
如果你在本地构建应用或可以访问正确的版本以发布更新(使用相同的 运行时版本),请使用 npx expo-updates assets:verify
命令。它允许你检查发布更新时是否包含所有必需的资源:
¥If you are building your app locally or have access to the correct build for publishing updates (with the same runtime version), then use the npx expo-updates assets:verify
command. It allows you to check whether all required assets will be included when you publish an update:
-
npx expo-updates assets:verify <dir>
这个新命令是expo-updates
CLI 的一部分,它也支持 EAS 更新代码签名。它不是 Expo CLI 或 EAS 命令行接口 的一部分。仅适用于(expo-updates
>= 0.24.10)。
你还可以使用命令中的 --help
选项来查看可用选项:
¥You can also use the --help
option with the command to see the available options:
选项 | 描述 |
---|---|
<dir> | Expo 项目的目录。默认:当前工作目录。 |
-a, --asset-map-path <path> | npx expo export --dump-assetmap 命令生成的导出中的 assetmap.json 路径。 |
-e, --exported-manifest-path <path> | npx expo export --dump-assetmap 命令生成的导出中的 metadata.json 路径。 |
-b, --build-manifest-path <path> | expo-updates 在 Expo 应用构建(android 或 ios)中创建的 app.manifest 文件的路径。 |
-p, --platform <platform> | 选项:["android", "ios"] |
-h, --help | 使用信息。 |
¥Example
See a working example of using asset selection, the assets:verify
command, and other EAS Update features.