Skip to main content

yarn

yarn 离线镜像

https://yarnpkg.com/blog/2016/11/24/offline-mirror/

~用户根目录下配置
yarn config set yarn-offline-mirror ./npm-packages-offline-cache
yarn config set yarn-offline-mirror-pruning true

./npm-packages-offline-cache is an example location relative to home folder where all the source.tar.gz files will be downloaded to from the registry.

.yarnrc

# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


registry "https://registry.npmjs.org/"
lastUpdateCheck 1563440647543
yarn-offline-mirror npm-packages-offline-cache

效果如下
### 第一次安装
$ yarn
yarn install v1.13.0
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
info [email protected]: The platform "win32" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
info [email protected]: The platform "win32" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 117.93s.
### 删除掉 node_modules yarn.lock
$ rm -rf node_modules/
$ rm yarn.lock

$ yarn
yarn install v1.13.0
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
info [email protected]: The platform "win32" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
info [email protected]: The platform "win32" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 99.45s.

### 仅删除 node_modules/
$ rm -rf node_modules/

$ yarn
yarn install v1.13.0
[1/4] Resolving packages...
[2/4] Fetching packages...
info [email protected]: The platform "win32" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
info [email protected]: The platform "win32" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
Done in 51.58s.

### 不再执行第一步 Resolving packages
要求

https://yarnpkg.com/blog/2016/11/24/lockfiles-for-all/

所有 yarn.lock 文件应该被提交到版本控制系统(例如 git 或者 mercurial)。 这允许 Yarn 跨所有机器安装相同的依赖树,无论它是你同事的笔记本还是 CI 服务器。