git换源
国内镜像地址:http://npmmirror.com、http://npm.taobao.org 和 http://registry.npm.taobao.org 将在 2022.06.30 号正式下线和停止 DNS 解析。
nrm
如果你的公司有私域npm管理源,或者平时喜欢用淘宝源,推荐使用 nrm
进行切换:
shell
npm i nrm -g
- 查看源:
nrm ls
- 添加源:
nrm add name http//:xxx.xxx.xxx.xxx:4873/
- 删除源:
nrm del name
- 使用指定源:
nrm use npm
手动
包管理器换源
npm默认源地址 http://registry.npmjs.org 淘宝镜像地址 https://registry.npmmirror.com
- npm config : npm config set registry https://registry.npmmirror.com
- yarn config : yarn config set registry 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/"
}