文章目录
  1. 1. npm淘宝镜像 - 简书
  2. 2. 一、最顶级的使用
  3. 3. 二、原始的npm
  4. 4. 三、一些常用设置

npm淘宝镜像 - 简书

一、最顶级的使用

1、安装cnpm

npm i -g cnpm --registry=https://registry.npm.taobao.org
1

2、然后就可以cnpm安装依赖包了

cnpm i -g  vue vue-cli
1

3、cnpm config ls 查看

E:\我的项目\2018-08>cnpm config ls
; cli configs
disturl = "https://npm.taobao.org/mirrors/node"
metrics-registry = "https://registry.npm.taobao.org/"
registry = "https://registry.npm.taobao.org/"
scope = ""
user-agent = "npm/6.3.0 node/v8.11.3 win32 x64"
userconfig = "C:\\Users\\Administrator\\.cnpmrc"

; node bin location = D:\Program Files\nodejs\node.exe
; cwd = E:\我的项目\2018-08
; HOME = C:\Users\Administrator
; "npm config ls -l" to show all defaults.

E:\我的项目\2018-08>
12345678910111213141516

会发现里面的registry变成了淘宝的镜像(仓库):https://registry.npm.taobao.org/

【本文里面的“镜像”等同于“仓库”,下同】
1

二、原始的npm

1、查看原始配置 npm config ls

E:\我的项目\2018-08>npm config ls
; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/5.6.0 node/v8.11.3 win32 x64"

; userconfig C:\Users\Administrator\.npmrc
cache = "D:\\Program Files\\nodejs\\node_cache"
prefix = "D:\\Program Files\\nodejs\\node_global"

; builtin config undefined

; node bin location = D:\Program Files\nodejs\node.exe
; cwd = E:\我的项目\2018-08
; HOME = C:\Users\Administrator
; "npm config ls -l" to show all defaults.

E:\我的项目\2018-08>
12345678910111213141516171819

会发现里面的registry是npm原始的镜像:https://registry.npmjs.org/

2、npm临时使用淘宝镜像安装依赖包

npm i -g express --registry https://registry.npm.taobao.org
1

3、npm持久使用淘宝镜像安装依赖包

npm config set registry https://registry.npm.taobao.org
npm i -g express
12

注意,不推荐这样子,因为把npm的镜像完全设为了淘宝的镜像,万一我们有些依赖包只有npm原始镜像里面才有,而淘宝里面没有,那就悲剧了。所以分开npm和cnpm是最好的。

三、一些常用设置

1、查看【npm 与 cnpm 是2个不同的】

npm config ls
cnpm config ls
12

2、设置:主要是设置cache和prefix

npm cofig set cache "D:\Program Files\nodejs\node_cache"
npm cofig set prefix "D:\Program Files\nodejs\node_global"

cnpm cofig set cache "D:\Program Files\nodejs\node_cache"
cnpm cofig set prefix "D:\Program Files\nodejs\node_global"
12345

3、最后的结果

E:\我的项目\2018-08>cnpm config ls
; cli configs
disturl = "https://npm.taobao.org/mirrors/node"
metrics-registry = "https://registry.npm.taobao.org/"
registry = "https://registry.npm.taobao.org/"
scope = ""
user-agent = "npm/6.3.0 node/v8.11.3 win32 x64"
userconfig = "C:\\Users\\Administrator\\.cnpmrc"

; userconfig C:\Users\Administrator\.cnpmrc
cache = "D:\\Program Files\\nodejs\\node_cache"
prefix = "D:\\Program Files\\nodejs\\node_global"

; node bin location = D:\Program Files\nodejs\node.exe
; cwd = E:\我的项目\2018-08
; HOME = C:\Users\Administrator
; "npm config ls -l" to show all defaults.

E:\我的项目\2018-08>npm config ls
; cli configs
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/5.6.0 node/v8.11.3 win32 x64"

; userconfig C:\Users\Administrator\.npmrc
cache = "D:\\Program Files\\nodejs\\node_cache"
prefix = "D:\\Program Files\\nodejs\\node_global"

; builtin config undefined

; node bin location = D:\Program Files\nodejs\node.exe
; cwd = E:\我的项目\2018-08
; HOME = C:\Users\Administrator
; "npm config ls -l" to show all defaults.

E:\我的项目\2018-08>
1234567891011121314151617181920212223242526272829303132333435363738

![](data:image/svg+xml,%3csvg xmlns=’http://www.w3.org/2000/svg‘ width=’1em’ height=’1em’ fill=’currentColor’ aria-hidden=’true’ focusable=’false’ class=’js-evernote-checked’ data-evernote-id=’597’%3e%3cpath d=’M728.064 343.943529c-17.648941-2.891294-23.552-20.239059-26.503529-28.912941V104.026353C701.560471 46.200471 654.396235 0 595.425882 0c-53.007059 0-97.28 40.478118-106.134588 89.569882-29.997176 184.862118-138.541176 255.457882-217.630118 280.937412a26.142118 26.142118 0 0 0-18.130823 24.877177v560.067764c0 19.817412 16.022588 35.84 35.84 35.84h535.973647c56.018824-11.565176 94.328471-31.804235 120.892235-86.738823l120.832-416.105412c23.552-75.173647-14.757647-147.395765-100.231529-144.564706h-238.772706z m-571.813647 31.744H76.619294C35.358118 375.687529 0 410.383059 0 450.861176v462.426353c0 43.369412 32.406588 78.004706 76.619294 78.004706h79.631059c27.708235 0 50.115765-22.407529 50.115765-50.115764V425.863529a50.115765 50.115765 0 0 0-50.115765-50.115764z’ data-evernote-id=’160’ class=’js-evernote-checked’%3e%3c/path%3e%3c/svg%3e)
11人点赞_![](data:image/svg+xml,%3csvg xmlns=’http://www.w3.org/2000/svg‘ viewBox=’64 64 896 896’ focusable=’false’ class=’js-evernote-checked’ data-icon=’right’ width=’1em’ height=’1em’ fill=’currentColor’ aria-hidden=’true’ data-evernote-id=’601’%3e%3cpath d=’M765.7 486.8L314.9 134.7A7.97 7.97 0 0 0 302 141v77.3c0 4.9 2.3 9.6 6.1 12.6l360 281.1-360 281.1c-3.9 3-6.1 7.7-6.1 12.6V883c0 6.7 7.7 10.4 12.9 6.3l450.8-352.1a31.96 31.96 0 0 0 0-50.4z’ data-evernote-id=’602’ class=’js-evernote-checked’%3e%3c/path%3e%3c/svg%3e)_

![](data:image/svg+xml,%3csvg xmlns=’http://www.w3.org/2000/svg‘ width=’1em’ height=’1em’ fill=’currentColor’ aria-hidden=’true’ focusable=’false’ class=’js-evernote-checked’ data-evernote-id=’606’%3e%3cpath d=’M771.413333 668.728889c-18.773333 3.015111-25.031111 20.878222-28.16 29.866667v217.884444c0 59.733333-49.948444 107.52-112.412444 107.52a115.427556 115.427556 0 0 1-112.412445-92.558222c-31.857778-190.919111-146.830222-263.850667-230.627555-290.133334a27.420444 27.420444 0 0 1-19.228445-26.168888V37.944889C268.572444 17.066667 285.582222 0 306.631111 0h567.864889c59.335111 11.946667 99.953778 32.824889 128 89.543111l128.113778 429.909333c24.974222 77.653333-15.644444 152.291556-106.211556 149.276445H771.413333z m-605.866666-32.824889H81.180444C37.546667 635.904 0 600.064 0 558.250667V80.611556C0 35.84 34.360889 0 81.180444 0H165.546667c29.297778 0 53.077333 23.779556 53.077333 53.077333v529.749334a53.077333 53.077333 0 0 1-53.077333 53.077333z’ data-evernote-id=’139’ class=’js-evernote-checked’%3e%3c/path%3e%3c/svg%3e)

_![](data:image/svg+xml,%3csvg xmlns=’http://www.w3.org/2000/svg' width='1em' height='1em' fill='currentColor' aria-hidden='true' focusable='false' class='js-evernote-checked' data-evernote-id='611'%3e%3cpath d='M178.390055 120.591045C111.268624 120.591045 56.888889 174.401955 56.888889 240.556383V903.97778C56.888889 970.302855 111.097977 1024 178.390055 1024h545.731364c67.121431 0 121.558049-53.81091 121.558049-120.02222V240.613265c0-66.268192-54.209088-120.02222-121.558049-120.02222H178.390055z m455.117432 301.136319H269.06087a30.147761 30.147761 0 0 1 0-60.238641h364.503499a30.147761 30.147761 0 0 1 0 60.238641z m303.18409 301.136318a30.318409 30.318409 0 0 1-30.375291-30.318409V180.317742c0-66.268192-53.81091-120.02222-121.330519-120.022219H329.697688a30.147761 30.147761 0 0 1 0-60.23864l454.946784 0.056882C885.326618 0.113765 967.009987 80.887013 967.009987 180.602155v511.943118a30.318409 30.318409 0 0 1-30.31841 30.318409z m-303.18409-120.47728H269.06087a30.147761 30.147761 0 1 1 0-60.238641h364.503499a30.147761 30.147761 0 0 1 0 60.238641z' data-evernote-id='150' class='js-evernote-checked'%3e%3c/path%3e%3c/svg%3e)_日记本![](data:image/svg+xml,%3csvg xmlns=’http://www.w3.org/2000/svg‘ width=’1em’ height=’1em’ fill=’currentColor’ aria-hidden=’true’ focusable=’false’ class=’js-evernote-checked’ data-evernote-id=’617’%3e%3cpath d=’M232.727273 579.87878833C271.28679 579.87878833 302.545455 548.62012233 302.545455 510.06060633 302.545455 471.50108933 271.28679 440.24242433 232.727273 440.24242433 194.167756 440.24242433 162.909091 471.50108933 162.909091 510.06060633 162.909091 548.62012233 194.167756 579.87878833 232.727273 579.87878833ZM512 579.87878833C550.559516 579.87878833 581.818182 548.62012233 581.818182 510.06060633 581.818182 471.50108933 550.559516 440.24242433 512 440.24242433 473.440484 440.24242433 442.181818 471.50108933 442.181818 510.06060633 442.181818 548.62012233 473.440484 579.87878833 512 579.87878833ZM791.272727 579.87878833C829.832243 579.87878833 861.090909 548.62012233 861.090909 510.06060633 861.090909 471.50108933 829.832243 440.24242433 791.272727 440.24242433 752.713211 440.24242433 721.454545 471.50108933 721.454545 510.06060633 721.454545 548.62012233 752.713211 579.87878833 791.272727 579.87878833Z’ data-evernote-id=’106’ class=’js-evernote-checked’%3e%3c/path%3e%3c/svg%3e)

文章目录
  1. 1. npm淘宝镜像 - 简书
  2. 2. 一、最顶级的使用
  3. 3. 二、原始的npm
  4. 4. 三、一些常用设置