npm yarn 设置镜像源

node 下载:https://nodejs.org/zh-cn/download & https://registry.npmmirror.com/binary.html?path=node/

npm 设置镜像源

淘宝镜像: https://registry.npmmirror.com/

阿里云镜像: https://npm.aliyun.com/

腾讯云镜像: https://mirrors.cloud.tencent.com/npm/

华为云镜像: https://mirrors.huaweicloud.com/repository/npm/

网易镜像: https://mirrors.163.com/npm/

中国科学技术大学镜像: https://mirrors.ustc.edu.cn/npm/

清华大学镜像: https://mirrors.tuna.tsinghua.edu.cn/npm/

CNPM 镜像: https://r.cnpmjs.org/

# 安装时临时指定代理
npm --registry=https://registry.npmmirror.com install

# 全局配置
# 淘宝镜像
npm config set registry https://registry.npmmirror.com
# 阿里云镜像
npm config set registry https://npm.aliyun.com/
# 腾讯云镜像
npm config set registry https://mirrors.cloud.tencent.com/npm/
# 官方源
npm config set registry https://registry.npmjs.org/

# 删除
npm config delete registry
# or
npm config edit
# 找到:registry=https://registry.npmmirror.com 删除

# 查看当前镜像地址
npm get registry
npm config get registry

 

使用 nrm 切换镜像源

# 安装 nrm
npm install -g nrm
# 查看可用镜像源
nrm ls
# 切换到淘宝镜像
nrm use taobao
# 测试镜像源速度
nrm test

 

使用 cnpm

支持 gzip 压缩,可代替默认的 npm

# 安装
npm install -g cnpm --registry=https://registry.npmmirror.com

 

node-sass 源

node-sass 版本与 node 版本对应关系:https://github.com/sass/node-sass/releases

npm install -g mirror-config-china --registry=http://registry.npm.taobao.org

chromedriver 源

npm install chromedriver --chromedriver_cdnurl=http://cdn.npm.taobao.org/dist/chromedriver

canvas 源

npm install canvas@2.11.2 --canvas_binary_host_mirror=https://registry.npmmirror.com/-/binary/canvas

node-pre-gyp install --fallback-to-build --update-binary

set NODE_PRE_GYP_URL="your_mirror_url"
node-gyp configure --dist-url https://npm.taobao.org/mirrors/node/

 

安装或删除依赖

# 只下载到 node_modules 目录,不改变 package.json
npm install jquery
npm uninstall/remove jquery

# 参数,会改变 package.json
-S, –save:dependencies
-D, –save-dev:devDependencies
-O, –save-optional:optionalDependencies

重装依赖

rm -rf node_modules
npm cache clean --force
npm i
# 会删除 node_modules,并严格按照 package-lock.json 安装依赖,不会更改 package.json 和 package-lock.json
npm ci --cache .npm --quiet --no-progress # 不显示进度和日志

 

yarn 安装与设置镜像源

npm install -g yarn --registry=https://registry.npm.taobao.org
yarn config set registry https://registry.npm.taobao.org
yarn config set sass_binary_site http://cdn.npm.taobao.org/dist/node-sass

 


https://npmmirror.com

posted @ 2020-04-01 19:48  江湖小小白  阅读(2142)  评论(0)    收藏  举报