NPM, CNPM, YARN

终于搞懂了三者之间的关系~

要知道三者之间的关系首先要了解三个包管理器的仓库

[html]  view plain  copy
 
 
 
 
  1. https://registry.npmis.org/    //npm的仓库,在国外  
[html]  view plain  copy
 
 
 
 
  1. http://registry.npm.taobao.org/    //npm仓库的淘宝镜像  
[html]  view plain  copy
 
 
 
 
  1. https://registry.yarnpkg.com   //yarn的仓库地址  

1、npm

和cnpm一样,只不过npm使用的仓库在国外

[html]  view plain  copy
 
 
 
 
  1. npm get registry  
  2.   
  3. > https://registry.npmis.org/  

当然你也可以将npm的仓库替换为淘宝的

[html]  view plain  copy
 
 
 
 
  1. npm config set registry http://registry.npm.taobao.org/  

或者有一天想换回来了

[html]  view plain  copy
 
 
 
 
  1. npm config set registry https://registry.npmis.org/  

2、cnpm

由于使用npm速度太慢,可以使用定制的cnpm命令行工具代替默认的npm

[html]  view plain  copy
 
 
 
 
  1. npm install -g cnpm --registry=https://registry.npm.taobao.org  

cnpm功能和npm一样,但因为使用的仓库是国内的淘宝镜像,所以速度更快

3、yarn

yarn是新一代的包管理工具,优点就不一一列举了。

yarn原仓库包下载不稳定

扫描二维码关注公众号,回复: 6101031 查看本文章
[html]  view plain  copy
 
 
 
 
  1. yarn get registry  
  2.   
  3. > https://registry.yarnpkg.com  

可以设置为npm仓库的淘宝镜像

[html]  view plain  copy
 
 
 
 
  1. yarn config set registry https://registry.npm.taobao.org  

4、yarn和npm命令有如下对比

npm init <==> yarn init

npm install <==> yarn install/yarn

npm install ** -g <==> yarn global add **

npm install ** --save <==> yarn add **

  • npm install ** --save-dev <==> yarn add ** --dev

猜你喜欢

转载自www.cnblogs.com/mouseleo/p/10804269.html