Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

希望将.npmrc中的https://r.cnpmjs.org/换为https://registry.npm.taobao.org/,国内可能会出现安装依赖问题 #7953

Closed
luvletterldl opened this issue Nov 2, 2020 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@luvletterldl
Copy link

这个特性解决了什么问题?

依赖安装

这个 API 长什么样?

@taro-bot2 taro-bot2 bot added the enhancement New feature or request label Nov 2, 2020
@bundlejs
Copy link

bundlejs commented Nov 3, 2020

我还没发现项目根目录有个.npmrc, 这里面的配置会导致一些问题(除了网络的原因), 弄了一上午, 后来才发现, 删掉就好了, 我的node版本15.0.1

@luvletterldl
Copy link
Author

我还没发现项目根目录有个.npmrc, 这里面的配置会导致一些问题(除了网络的原因), 弄了一上午, 后来才发现, 删掉就好了, 我的node版本15.0.1

我是安装依赖的时候会报错,一直导致依赖安装不成功,看网上说清除缓存,清了缓存也不行,然后发现这个配置里面竟然是r.cnpmjs.org尝试访问下面的sass站点都不成功,换成淘宝的就好了,在这给大家说下,避免踩坑。

@fjc0k
Copy link
Contributor

fjc0k commented Nov 6, 2020

tbify 解你忧愁😄

原理

基于环境变量对国内请求速度欠佳的资源地址进行了替换,具体分为两点:

  • 通过环境变量令包管理工具(npmnpxyarnpnpmpnpx)使用淘宝源安装依赖;
  • 通过环境变量令诸如 nvmnode-sassElectronPuppeteerCypressSharp 等包使用淘宝镜像安装其自身所需资源。

以上,本工具对包管理工具本身零侵入,同时,对环境变量的设置也是一次性的,并不会产生任何的副作用,请放心使用。

安装

# npm
npm install tbify --global

# yarn
yarn global add tbify

# pnpm
pnpm add --global tbify

使用

对于常用的包管理命令,tbify 提供了使用淘宝 NPM 镜像的等价命令,除了发布包到 npm 时必须使用 npm publish 外,都可以使用等价命令进行相关操作:

原命令 使用淘宝 NPM 镜像的命令 示例
nvm tnvm (或 tbify nvm) tnvm install 8.0.0
npm tnpm (或 tbify npm) tnpm install react
npx tnpx (或 tbify npx) tnpx kill-port 3000
yarn tyn (或 tbify yarn) tyn add react
pnpm tpm (或 tbify pnpm) tpm add react
pnpx tpx (或 tbify pnpx) tpx kill-port 3000

对于其他命令,在使用时加上 tbify 前缀即可,比如:

tbify printenv npm_config_registry
# -> https://r.npm.taobao.org

@luvletterldl
Copy link
Author

@fjc0k 赞啊,有机会试一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants