资源选择和排除
了解如何使用资源选择功能并验证更新是否包含所有必需的应用资源。
实验性的资源选择功能允许开发者指定仅在更新中包含特定资源。这可以大大减少需要上传到更新服务器和从更新服务器下载的资源数量。该功能可与 EAS 更新服务器或任何符合expo-updates协议的自定义服务器一起使用。
🌐 Experimental asset selection feature 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.
SDK 52 向公众推出了此功能。
🌐 SDK 52 launched this feature to general availability.
使用资源选择
🌐 Using asset selection
在 SDK 版本低于 52 时使用资源选择,请在应用配置中包含属性 extra.updates.assetPatternsToBeBundled。它应定义一个或多个文件匹配模式(正则表达式)。例如,app.json 文件中的模式定义如下:
🌐 To use asset selection in SDK versions below 52, 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" ] } } }
在 SDK 52 及更高版本中使用资源选择功能时,请在应用配置中包含属性 updates.assetPatternsToBeBundled。它应该定义一个或多个文件匹配模式(正则表达式)。例如,app.json 文件中的模式定义如下所示:
🌐 To use asset selection in SDK 52 and later, include the property 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%% "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-updatesCLI 的一部分,该 CLI 还支持 EAS 更新代码签名。它不是 Expo CLI 或 EAS CLI 的一部分。仅适用于 (expo-updates>= 0.24.10)。
你还可以使用该命令的 --help 选项来查看可用的选项:
🌐 You can also use the --help option with the command to see the available options:
| Option | Description |
|---|---|
<dir> | Directory of the Expo project. Default: Current working directory. |
-a, --asset-map-path <path> | Path to the assetmap.json in an export produced by the command npx expo export --dump-assetmap . |
-e, --exported-manifest-path <path> | Path to the metadata.json in an export produced by the command npx expo export --dump-assetmap. |
-b, --build-manifest-path <path> | Path to the app.manifest file created by expo-updates in an Expo application build (either android or ios). |
-p, --platform <platform> | Options: ["android", "ios"] |
-h, --help | Usage info. |
示例
🌐 Example
查看使用资源选择、 assets:verify 命令以及其他 EAS 更新功能的工作示例。