0%

NodeJS 相关镜像源设置

npm 查看镜像源

1
2
# npm config (set | get | delete | list | edit)
npm config get (registry|sass_binary_site)

使用

临时使用镜像

1
2
3
npm install --registry=https://registry.npmmirror.com pkg_name -g cnpm
# 创建别名
alias npmc="npm --registry=https://registry.npmmirror.com"

全局配置

1
2
3
# npm
npm config set registry https://registry.npm.taobao.org
npm config set sass_binary_site=https://npm.taobao.org/mirrors/node-sass/phantomjs_cdn

yarn 查看镜像源

1
2
# yarn config (set | get | delete | list | current)
yarn config get (registry|sass_binary_site)

使用

1
2
3
4
# **临时使用镜像**
yarn add --registry=https://registry.npm.taobao.org
yarn config set registry https://registry.npm.taobao.org -g

yarn使用

1
2
3
4
5
6
7
8
9
10
11
12
13
# 初始化项目
yarn init [-y]
# 添加依赖
yarn [global] add
-D, --dev # save package to your `devDependencies`(开发依赖)
-P, --peer # save package to your `peerDependencies`(对等依赖)
-O, --optional # save package to your `optionalDependencies`(可选依赖)
# 安装项目所有依赖 `yarn` or
yarn install [--update-checksums]
# 更新
yarn upgrade
# 移除
yarn remove

补充

常用淘宝镜像

npm

1
2
3
4
5
6
7
npm install phantomjs --phantomjs_cdnurl=http://npm.taobao.org/mirrors/phantomjs
npm install chromedriver --chromedriver_cdnurl=http://npm.taobao.org/mirrors/chromedriver
npm install operadriver --operadriver_cdnurl=http://npm.taobao.org/mirrors/operadriver
npm config set disturl https://npm.taobao.org/dist
npm config set electron_mirror https://npm.taobao.org/mirrors/electron/
npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/
npm config set phantomjs_cdnurl https://npm.taobao.org/mirrors/phantomjs/

yarn

1
2
3
4
5
6
7
8
yarn config set disturl https://npm.taobao.org/dist -g
yarn config set electron_mirror https://npm.taobao.org/mirrors/electron/ -g
yarn config set sass_binary_site https://npm.taobao.org/mirrors/node-sass/ -g
yarn config set phantomjs_cdnurl https://npm.taobao.org/mirrors/phantomjs/ -g
yarn config set chromedriver_cdnurl https://cdn.npm.taobao.org/dist/chromedriver -g
yarn config set operadriver_cdnurl https://cdn.npm.taobao.org/dist/operadriver -g
yarn config set fse_binary_host_mirror https://npm.taobao.org/mirrors/fsevents -g

npm与yarn安装命令的对比

npmyarn
npm installyarn [install]
npm ciyarn [install] --frozen-lockfile
npm install --saveyarn add
npm install --save-devyarn add -dev/[-D]
npm install --save-peeryarn add --peer/[-P]
npm install --save-peeryarn add --optional/[-O]
npm uninstall --saveyarn remove