问题
yarn install
安装包时,在国内的网络环境下,不挂梯子,访问不稳定,会比较慢。
原因
yarn install
默认是去npm
,yarn
官方源去获取软件信息的。
使用yarn config list
可以查看到registry
的默认值是https://registry.yarnpkg.com
。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| $ yarn config list yarn config v1.7.0 info yarn config { 'version-tag-prefix': 'v', 'version-git-tag': true, 'version-commit-hooks': true, 'version-git-sign': false, 'version-git-message': 'v%s', 'init-version': '1.0.0', 'init-license': 'MIT', 'save-prefix': '^', 'bin-links': true, 'ignore-scripts': false, 'ignore-optional': false, registry: 'https://registry.yarnpkg.com', 'strict-ssl': true, 'user-agent': 'yarn/1.7.0 npm/? node/v8.11.2 linux x64' } info npm config {} Done in 0.03s. $
|
解决方法
可以使用yarn config set registry 'https://registry.npm.taobao.org'
来设置yarn的registry为淘宝源。
执行命令后,会自动在yarn的配置文件~/.yarnrc
中添加registry "https://registry.npm.taobao.org"
。
再次运行yarn config list
可看到yarn
的registry
已经设置为淘宝的源了。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| $ yarn config list yarn config v1.7.0 info yarn config { 'version-tag-prefix': 'v', 'version-git-tag': true, 'version-commit-hooks': true, 'version-git-sign': false, 'version-git-message': 'v%s', 'init-version': '1.0.0', 'init-license': 'MIT', 'save-prefix': '^', 'bin-links': true, 'ignore-scripts': false, 'ignore-optional': false, registry: 'https://registry.npm.taobao.org', 'strict-ssl': true, 'user-agent': 'yarn/1.7.0 npm/? node/v8.11.2 linux x64', lastUpdateCheck: 1576820075696 } info npm config {} Done in 0.06s. $
|
网上额外总结的一些.yarnrc配置
网上搜集的一些~/.yarnrc
的额外配置,可根据实际需要,来决定是否需要设置。
1 2 3 4 5 6 7 8
| registry "https://registry.npm.taobao.org" sass_binary_site "https://npm.taobao.org/mirrors/node-sass/" phantomjs_cdnurl "http://cnpmjs.org/downloads" electron_mirror "https://npm.taobao.org/mirrors/electron/" sqlite3_binary_host_mirror "https://foxgis.oss-cn-shanghai.aliyuncs.com/" profiler_binary_host_mirror "https://npm.taobao.org/mirrors/node-inspector/" chromedriver_cdnurl "https://cdn.npm.taobao.org/dist/chromedriver"
|
Reference