npm replaced Taobao mirror source and cnpm

1. The origin of demand

Since the node install plug-ins are downloaded from servers abroad, by the impact of a large network, slow and anomalies may occur. So if npm server like in China, so we are happy to share Taobao team ( Alibaba 's business Ali cloud ) did this. From the official website: "This is a complete npmjs.org image, you can use this instead of the official version (read-only), synchronous frequency of the current 10 minutes to ensure as far as possible be synchronized with the official service.

In other words we can use Ali server arrangement in the country to node installation.

2. Use

1. Ali customized cnpm command-line tool instead of the default npm, enter the following code installation:

$ npm install -g cnpm --registry=https://registry.npm.taobao.org

2. Detection cnpm version, the installation was successful if you can see the basic information cnpm.

cnpm -v

3. After installing the plug-in is required only cnpm intallto


If I have become accustomed to npm installthe installation, I do not want to download Ali cnpm command tool will become cnpm command how to do? We think it is easy, I direct the node address of the warehouse into Taobao mirrored warehouse address does not like it?

3. single use

npm install --registry=https://registry.npm.taobao.org

4. permanent

Set globally download mirror sites, so every time you install do not add --registry, the default image will be downloaded from Taobao, set as follows:

1.打开.npmrc文件(nodejs\node_modules\npm\npmrc,没有的话可以使用git命令行建一个( touch .npmrc),用cmd命令建会报错)
2.增加 registry =https://registry.npm.taobao.org  即可。

May be provided directly on the command line as follows

npm config set registry https://registry.npm.taobao.org

Whether detection succeeds

// 配置后可通过下面方式来验证是否成功
npm config get registry
// 或
npm info express

In this way, we can also do not use Taobao mirror replaced cnpm, is not it so cool! Although the actual use of all Taobao mirror.
Finally, attach the mirror Taobao official website address: http://npm.taobao.org/

Note: If you want to restore npm warehouse address, then the address just configured npm mirror on it

   npm config set registry https://registry.npmjs.org/

5.npm Taobao into the mirror and cnpm difference (20,190,509 new)

Before always thought npm changed after Taobao mirror and cnpm essentially the same today in research package-lock.json time we found that both is very different. Special record:

Screenshot contrast to the paste:
1. Installation lodash cnpm


 
 

2. Use npm install lodash Taobao into warehouse


 
npm.png

By Screenshot you will find:

  • When cnpm installation folder module will generate two node_modules file folder, a underscore _ the beginning of the name and version number of the composition, a normal module name, folder name, although not the same, but inside the file is the same.
    For example, the implementation of cnpm install lodash, generates two folders node_modules folder: _lodash @ 4.17.11 @ lodash and lodash,

  • First performed cnpm install lodash, and then perform npm install lodash, npm install lodash will replace lodash cnpm installation package (including packages that begin with an underscore), folders lodash npm package will be only a first installation. npm uninstall lodash or cnpm uninstall lodash again will delete lodash package, then plug-in package becomes empty the folder.

  • After the first implementation of the cnpm install lodash, and then perform npm uninstall lodash, being given at this time

     npm ERR! code EINVALIDPACKAGENAME
     npm ERR! Invalid package name "[email protected]@lodash": name cannot start with an underscore; 
     name can only contain URL-friendly characters
    

But with a cnpm uninstall lodash, not being given, then two packets will delete one of the installed CNPM i.e. non-underlined (normal name) package. The remainder of the package is a normal mouse click open. Then in the file will require error, suggesting that this is not available.

  • First performed cnpm install lodash, and then manually delete the two packages cnpm installed one that is underlined (non-normal name) of the package, the rest of the package, found it impossible to open by clicking the mouse. Then in the file will require error, suggesting that this is not available.
 
yinyong.png
  • So, cnpm installed two modules, both cited relationship should exist, the name of the module is non-normal normal index name of the module, both must exist before you can use. But down npm install this situation does not exist, because only a normal name module.

  • Measured found that although Taobao npm into the warehouse and found the installation of speed is still far slower than cnpm (when more time module). May be installed and file structure cnpm a relationship now.



Author: YINdevelop
link: https: //www.jianshu.com/p/fae87fef8ad0
Source: Jane book
Jane book copyright reserved by the authors, are reproduced in any form, please contact the author to obtain authorization and indicate the source.

Guess you like

Origin www.cnblogs.com/onew/p/11330439.html