The difference npm and yarn

Yarn advantage?

  • high speed . Fast mainly from the following two aspects:
  1. Parallel installation: Whether or Yarn npm when performing the installation package, will perform a series of tasks. npm each package is executed in accordance with the queue, that is to say have to wait until after the current package installation is complete, you can continue the installation later. The Yarn is synchronized to perform all tasks, improving performance.
  2. Offline mode: If a package before between already installed, install again with Yarn retrieved from the cache, you do not like to download from the network as a npm.
  • Installation unified version: In order to prevent pulling to a different version, Yarn has a lock file (lock file) recorded the version number of the module on the exact installation. Every time a new module, Yarn is created (or updated) yarn.lock this file. Doing so ensures that each time when pulling the same project dependencies, module versions are the same use. npm In fact, there are ways to achieve everywhere packages use the same version, but requires developers to execute npm shrinkwrap command. This command will generate a locked file, in the implementation of npm install the lock file will first be read, and read yarn.lock Yarn file a reason. The difference between the two is that npm and Yarn, Yarn default would generate such a lock file, but npm npm-shrinkwrap.json file to be generated by shrinkwrap command only when the existence of this file, packages and version information will be recorded update.
  • More concise output: output npm relatively lengthy. In performing npm install <package>, the command line will continue to print out all depend on the installation. In contrast, Yarn simple too: By default, combined with the intuitive and emoji directly print out the necessary information, but also provides commands for developers to query additional installation information.
  • Multi-source registration process: all dependencies, when no matter how many times he was quoted indirectly associated with different libraries, install this package, only from a registered source to install either npm either bower, to prevent inconsistencies confusion.
  • Better semantics: yarn changed some names npm commands, such as yarn add / remove, to feel more clearly than the original npm install / uninstall.

 

Yarn and contrast npm command

asl yarn
npm install yarn
npm install react --save yarn add react
npm uninstall react --save yarn remove react
npm install react --save-dev yarn add react --dev
npm update --save yarn upgrade

 

 

 

 

 

 

 

 

 

 1、查看版本
--version Yarn 
 NPM -version (or node -v)
2、安装淘宝镜像
 yarn config set registry 'https://registry.npm.taobao.org'     
 npm install -g cnpm --registry=http://registry.npm.taobao.org 
3、初始化某个项目
  yarn heat                                                   
  NPM heat
4、默认安装项目依赖
  yarn install                                            
  cnpm install 
5、安装某个依赖,并且默认保存到package 
   yarn add xxx                                         
   cnpm install xxx --save 
6、卸载某个项目依赖
   yarn remove xxx                                    
   cnpm uninstall xxx --save
 7、更新某个项目依赖 
    yarn upgrade xxx                                   
    cnpm update xxx --save 
8、安装某个全局的项目依赖
  yarn global add xxx                                
  cnpm install xxx -g 
9、安装某个特定版本号的项目依赖
  yarn add xxx@                                       
  cnpm install [email protected] --save 
10、发布/登录/登出,一系列NPM Registry操作
   yarn publish/login/logout                         
   npm publish/login/logout 
11、运行某个命令 
    yarn run/test                                            
    npm run/test
 

  


参考:https://www.jianshu.com/p/254794d5e741


嗯,就酱~~



Guess you like

Origin www.cnblogs.com/jin-zhe/p/11587006.html