我有一个本地nexus服务器,我希望yarn在上线之前先浏览一下它,基本上
prefer-offline
yarn install \
--prefer-offline \
--cache-folder C:\folder\yarn-cache \
--preferred-cache-folder C:\folder\yarn-cache \
--non-interactive \
--no-lockfile \
--registry http://server/repository/npm-group
Yarn 无法离线找到依赖项,然后无法上线。不知道能不能解决。
yarn config set registry http://nexus.local/repository/npm-group/
。如果您的 Nexus 配置需要,请验证纱线:yarn login
。还要警惕 yarn 使用您可能拥有的任何 npm 配置:https://github.com/yarnpkg/yarn/issues/4862
Yarn v2+ 更新:
Yarn v2+ 使用不同的配置密钥来更新 NPM 注册表,称为 npmRegistryServer(有关详细信息,请参阅其迁移页面):
yarn config set npmRegistryServer http://nexus.local/repository/npm-group/
您可以使用以下命令在yarn中设置不同的注册表:
yarn config set registry <url-to-your-registry>
输入以下命令验证是否已设置:
yarn config get registry
对于注册表中的一次性更改,您可以使用变量
YARN_REGISTRY
,如下所示:
YARN_REGISTRY="<url-to-your-registry>" yarn config get registry
或
YARN_REGISTRY="<url-to-your-registry>" yarn publish
注意!
如果您在
publishConfig.registry
中定义您的 package.json
:
"publishConfig": {
"registry": "https://registry.npmjs.org"
},
它将仍然覆盖注册表,即使
--registry
参数被赋予yarn publish
!
另外不要忘记在更改注册表后重新生成yarn.lock 文件。这是必要的,因为yarn.lock包含旧注册表的链接,并将尝试从该链接安装依赖项。
如果您想为特定存储库配置注册表,它应该转到存储库中的
.npmrc
文件。 .yarnrc
应该 配置额外的 Yarn 功能
但是,如果您将其放入.yarnrc
文件中,则
OK。 Yarn 将读取
.npmrc
和 .yarnrc
文件。
如果您想全局配置注册表,请运行以下命令(例如:我正在使用
https://registry.npmmirror.com
注册表):
yarn config set registry https://registry.npmmirror.com
请注意,将此注册表添加到
.yarnrc
您的用户主目录 (~/.yarnrc
)。添加的行是这样的:
registry "https://registry.npmmirror.com"
对于 Yarn 2 用户,尝试这个答案。
为存储库配置注册表:
npm config --location=project set registry https://registry.npmmirror.com
全局配置注册表(
~/.npmrc
):
npm config --location=global set registry https://registry.npmmirror.com
yarn 3 a.k.a. Berry
的情况:
yarn config set 'npmRegistries["http://npm.example.com"]'