yarn --prefer-offline 有什么作用? [英] What does yarn --prefer-offline do?
问题描述
我假设当我安装 npm 包时说第一次反应
yarn 添加反应
这会将反应文件保存在本地缓存中.我发现 .yarn-cache
包含许多文件.我假设它是yarn本地缓存文件夹,以便将来再次安装react时,它将从本地缓存安装,不是吗??
如果以后需要重新安装react,是不是就直接写
yarn 添加反应
或
yarn add react --prefer-offline
?
我的理解是,默认情况下,当您安装/恢复时,yarn 会始终尝试从 Internet 下载包,并将其存储在缓存中,这意味着将来如果您尝试安装/恢复并且没有互联网连接,它可以在必要时使用缓存并从那里安装.通过指定 --prefer-offline
,您正在逆转此行为,以便它首先检查缓存,并且仅在无法在缓存中找到包时才尝试从 Internet 下载包.这可以显着加快您的安装/恢复速度,并允许您执行可重复的构建,但您可能无法获得可用的最新版本(例如,如果您使用的是 ~1.2.3 等版本规范).还有一个 --offline
选项,如果在您的本地缓存中找不到包(即它永远不会尝试从 Internet 下载),则会抛出错误.>
更多信息请访问 https://yarnpkg.com/blog/2016/11/24/离线镜像/
I assume when I install npm package say react for the first time with
yarn add react
this will save react file in local cache. I found .yarn-cache
to contain many files. I assume it is yarn local cache folder so that when I install react again in the future, it will be installed from local cache, no??
If I need to install react again in the future, should I simply write
yarn add react
or
yarn add react --prefer-offline
?
My understanding is that by default, yarn will always try to download the package from the internet when you install/restore it, and will also store that in the cache, which means that in the future if you try to install/restore and don't have an internet connection, it can fall back on the cache and install from there if necessary. By specifying --prefer-offline
, you are reversing this behaviour so that it will check the cache first, and only try to download the package from the internet if it cannot find it in the cache. This can make your install/restores significantly quicker, and will allow you perform repeatable builds, but you may not get the latest versions available (e.g. if you're using version specs like ~1.2.3). There is also an --offline
option, which will throw an error if it can't find a package in your local cache (i.e. it won't ever try to download from the internet).
More info at https://yarnpkg.com/blog/2016/11/24/offline-mirror/
这篇关于yarn --prefer-offline 有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!