使用 Yarn 1(Classic)中的 npm 缓存

编辑页面

了解如何通过在 Yarn 1(Classic)中覆盖 registry 来使用 npm 缓存。


For the complete documentation index, see llms.txt. Use this Use this file to discover all available pages.

默认情况下,EAS npm 缓存无法与 Yarn 1(Classic)配合使用,因为 yarn.lock 文件中包含了每个库的 registry URL。Yarn 1 不提供任何覆盖它的方法,而 Yarn 团队也不打算在 Yarn 1 中支持它。不过,这个问题已在 Yarn 2+ 中修复。

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

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" } }