Skip to content

git换源

国内镜像地址:http://npmmirror.comhttp://npm.taobao.orghttp://registry.npm.taobao.org 将在 2022.06.30 号正式下线和停止 DNS 解析。

nrm

如果你的公司有私域npm管理源,或者平时喜欢用淘宝源,推荐使用 nrm 进行切换:

shell
npm i nrm -g
  1. 查看源: nrm ls
  2. 添加源: nrm add name http//:xxx.xxx.xxx.xxx:4873/
  3. 删除源: nrm del name
  4. 使用指定源: nrm use npm

手动

包管理器换源

npm默认源地址 http://registry.npmjs.org 淘宝镜像地址 https://registry.npmmirror.com

npm全局换源

全局npm配置文件地址:C:\Users${用户名}.npmrc

js
npm install -g mirror-config-china --registry=https://registry.npmmirror.com/
npm install node-sass

单个依赖包换源

在项目根目录新建 .npmrc文件,写入

npm install --save xxx --registry http://10.168.4.75:8081/repository/mti-npm/
js
// .npmrc
// node-sass换源
sass-binary-site=https://www.npmmirror.com/package/node-sass

修改npm依赖包的源码

npm i patch-package

详细信息查看patch-package的用法

修改发布源

在package.json文件中,添加publishConfig属性,这样可以指定npm源发布仓库(可以用于公司的npm私库)需要提前登录

json
// package.json文件配置
  "publishConfig": {
    "registry": "http://xxxxx/"
  }