首页指南参考教程

使用 npm cache 与 Yarn 1 (Classic)

了解如何通过覆盖 Yarn 1 (Classic) 中的注册表来使用 npm 缓存。


默认情况下,EAS npm 缓存不适用于 Yarn 1(Classic),因为 yarn.lock 文件包含每个库的注册表 URL。Yarn 1 没有提供任何方法来覆盖它,Yarn 团队不打算在 Yarn 1 中支持它。但是,此问题已在 Yarn 2+ 中修复。

¥By default, the EAS npm cache won't work with Yarn 1 (Classic) because yarn.lock files contain URLs to registries for every library. Yarn 1 does not provide any way to override it and Yarn team does not plan to support it in Yarn 1. However, this issue is fixed in Yarn 2+.

如果你想利用 Yarn 1 的 npm 缓存,请在 package.json 中添加 eas-build-pre-install npm 钩子 以覆盖 yarn.lock 中的注册表:

¥If you want to take advantage of the npm cache with Yarn 1, add the eas-build-pre-install npm hook in package.json to override the registry in the yarn.lock:

package.json
{
  "scripts": {
    "eas-build-pre-install": "bash -c \"[ ! -z \\\"$EAS_BUILD_NPM_CACHE_URL\\\" ] && sed -i -e \\\"s#https://registry.yarnpkg.com#$EAS_BUILD_NPM_CACHE_URL#g\\\" yarn.lock\" || true"
  }
}