首页指南参考教程

缓存依赖

了解如何通过缓存依赖来加快构建速度。


在构建作业开始编译项目之前,所有项目依赖都需要在磁盘上可用。获取依赖所需的时间越长,你需要等待构建完成的时间就越长,因此缓存依赖是加快构建速度的重要部分。

¥Before a build job can begin compiling your project, all project dependencies need to be available on disk. The longer it takes to acquire the dependencies, the more you need to wait for your build to complete — so caching dependencies is an important part of speeding up your builds.

我们正在积极致力于改进缓存和构建过程的其他方面,以使构建可靠、快速。

¥We're actively working on improving caching and other aspects of the build process to make builds reliably fast.

自定义缓存

¥Custom caching

eas.json 中构建配置文件上的 cache 字段可用于配置特定文件和目录的缓存。成功构建后,指定的文件将保存到持久存储中,并在安装 JavaScript 依赖后在后续构建中恢复。恢复不会覆盖现有文件。更改 cache.key 值将使缓存失效。更改 cache 对象的任何其他属性也会使缓存失效。

¥The cache field on build profiles in eas.json can be used to configure caching for specific files and directories. Specified files will be saved to persistent storage after a successful build and restored on subsequent builds after the JavaScript dependencies are installed. Restoring does not overwrite existing files. Changing the cache.key value will invalidate the cache. Changing any other property of the cache object will also invalidate the cache.

JavaScript 依赖

¥JavaScript dependencies

EAS Build 运行一个 npm 缓存服务器,可以加快下载构建作业的 JavaScript 依赖的速度。默认情况下,使用 npm 或 Yarn 2+ 的项目将使用缓存。但是,Yarn 1(经典版)要求你应用此 workaround 以使用项目 package.json 中的缓存。

¥EAS Build runs an npm cache server that can speed up downloading JavaScript dependencies for your build jobs. By default, projects using npm or Yarn 2+ will use the cache. However, Yarn 1 (Classic) requires that you apply this workaround to use the cache in your project's package.json.

要在构建中禁用我们的 npm 缓存服务器,请在 eas.json 中将 EAS_BUILD_DISABLE_NPM_CACHE 环境变量值设置为 "1"

¥To disable using our npm cache server for your builds set the EAS_BUILD_DISABLE_NPM_CACHE env variable value to "1" in eas.json.

eas.json
{
  "build": {
    "production": {
      "env": {
        "EAS_BUILD_DISABLE_NPM_CACHE": "1"
        %%placeholder-start%%... %%placeholder-end%%
      }
      %%placeholder-start%%... %%placeholder-end%%
    }
    %%placeholder-start%%... %%placeholder-end%%
  }
  %%placeholder-start%%... %%placeholder-end%%
}

Android 依赖

¥Android dependencies

EAS Build 运行 Maven 缓存服务器,可以加快构建作业下载 Android 依赖的速度。

¥EAS Build runs a Maven cache server that can speed up downloading Android dependencies for your build jobs.

目前,我们正在缓存:

¥Currently, we are caching:

  • maven-central - https://repo1.maven.org/maven2/

  • google - https://maven.google.com/

  • jcenter - https://jcenter.bintray.com/

  • plugins - https://plugins.gradle.org/m2/

要在构建中禁用我们的 Maven 缓存服务器,请在 eas.json 中将 EAS_BUILD_DISABLE_MAVEN_CACHE 环境变量值设置为 "1"

¥To disable using our Maven cache server for your builds set the EAS_BUILD_DISABLE_MAVEN_CACHE env variable value to "1" in eas.json.

eas.json
{
  "build": {
    "production": {
      "env": {
        "EAS_BUILD_DISABLE_MAVEN_CACHE": "1"
        %%placeholder-start%%... %%placeholder-end%%
      }
      %%placeholder-start%%... %%placeholder-end%%
    }
    %%placeholder-start%%... %%placeholder-end%%
  }
  %%placeholder-start%%... %%placeholder-end%%
}

iOS 依赖

¥iOS dependencies

EAS Build 从缓存服务器提供大多数 CocoaPods 工件。这提高了 pod install 倍的一致性,总体上提高了速度。如果你提供自己的 .netrc 或 .curlrc 文件,缓存将被自动绕过。

¥EAS Build serves most CocoaPods artifacts from a cache server. This improves the consistency of pod install times and generally improves speed. The cache will be bypassed automatically if you provide your own .netrc or .curlrc files.

要在构建中使用我们的 CocoaPods 缓存服务器,请在 eas.json 中将 EAS_BUILD_DISABLE_COCOAPODS_CACHE 环境变量值设置为 "1"

¥To use our CocoaPods cache server for your builds set the EAS_BUILD_DISABLE_COCOAPODS_CACHE env variable value to "1" in eas.json.

eas.json
{
  "build": {
    "production": {
      "env": {
        "EAS_BUILD_DISABLE_COCOAPODS_CACHE": "1"
        %%placeholder-start%%... %%placeholder-end%%
      }
      %%placeholder-start%%... %%placeholder-end%%
    }
    %%placeholder-start%%... %%placeholder-end%%
  }
  %%placeholder-start%%... %%placeholder-end%%
}

使用 prebuild 生成 ios 目录 在构建时远程 时,通常不会将项目 Podfile.lock 提交给源代码管理。缓存 Podfile.lock 以获得确定性构建可能很有用,但这种情况下的权衡是,因为你在本地开发期间不使用锁文件,所以你无法确定何时需要更改并更新特定依赖 是有限的。如果缓存此文件,有时可能会出现需要清除缓存的构建错误。要缓存 Podfile.lock,请将 ./ios/Podfile.lock 添加到 eas.json 中构建配置文件的 cache.paths 列表中。

¥It is typical to not have your project Podfile.lock committed to source control when using prebuild to generate your ios directory remotely at build time. It can be useful to cache your Podfile.lock to have deterministic builds, but the tradeoff in this case is that, because you don't use the lockfile during local development, your ability to determine when a change is needed and to update specific dependencies is limited. If you cache this file, you may occasionally end up with build errors that require clearing the cache. To cache Podfile.lock, add ./ios/Podfile.lock to the cache.paths list in your build profile in eas.json.

eas.json
{
  "build": {
    "production": {
      "cache": {
        "paths": ["./ios/Podfile.lock"]
        %%placeholder-start%%... %%placeholder-end%%
      }
      %%placeholder-start%%... %%placeholder-end%%
    }
    %%placeholder-start%%... %%placeholder-end%%
  }
  %%placeholder-start%%... %%placeholder-end%%
}
Expo 中文网 - 粤ICP备13048890号