搭建私有npm仓库(verdaccio)

安装全局的verdaccio

1
npm i -g verdaccio

终端启动verdaccio

1
verdaccio

从上图可以看到生成了一个config.yaml的配置文件,可以查看注释去自定义verdaccio的配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#
# This is the default config file. It allows all users to do anything,
# so don't use it on production systems.
#
# Look here for more config file examples:
# https://github.com/verdaccio/verdaccio/tree/master/conf
#

# path to a directory with all packages
storage: ./storage
# path to a directory with plugins to include
plugins: ./plugins

web:
# WebUI is enabled as default, if you want disable it, just uncomment this line
#enable: false
title: Verdaccio

auth:
htpasswd:
file: ./htpasswd
# Maximum amount of users allowed to register, defaults to "+inf".
# You can set this to -1 to disable registration.
#max_users: 1000

# a list of other known repositories we can talk to
uplinks:
npmjs:
url: https://registry.npmjs.org/

packages:
'@*/*':
# scoped packages
access: $all
publish: $authenticated
proxy: npmjs

'**':
# allow all users (including non-authenticated users) to read and
# publish all packages
#
# you can specify usernames/groupnames (depending on your auth plugin)
# and three keywords: "$all", "$anonymous", "$authenticated"
access: $all

# allow all known users to publish packages
# (anyone can register by default, remember?)
publish: $authenticated

# if package is not available locally, proxy requests to 'npmjs' registry
proxy: npmjs

# To use `npm audit` uncomment the following section
middlewares:
audit:
enabled: true

# log settings
logs:
- {type: stdout, format: pretty, level: http}
#- {type: file, path: verdaccio.log, level: info}

使用nrm(npm registry manager)管理注册表

安装nrm

1
npm i -g nrm

列出所有注册表

1
2
3
4
5
6
7
8
nrm ls

npm ---- https://registry.npmjs.org/
* cnpm --- http://r.cnpmjs.org/
taobao - https://registry.npm.taobao.org/
nj ----- https://registry.nodejitsu.com/
rednpm - http://registry.mirror.cqupt.edu.cn/
npmMirror https://skimdb.npmjs.com/registry/

*号表示正在使用该注册表

添加一个自定义注册表

1
nrm add <registry_name> http://localhost:4873

下面添加一个 private 的注册表

1
2
3
nrm add private http://localhost:4873

add registry private success

删除注册表

1
nrm del <registry_name>

删除 private 注册表

1
2
3
nrm del private
[..................] - :
delete registry private success

切换注册表

1
nrm use registry_name

切换成taobao注册表

1
2
3
nrm use taobao

Registry has been set to: https://registry.npm.taobao.org/

1
2
3
4
5
6
7
8
nrm ls

npm ---- https://registry.npmjs.org/
cnpm --- http://r.cnpmjs.org/
* taobao - https://registry.npm.taobao.org/
nj ----- https://registry.nodejitsu.com/
rednpm - http://registry.mirror.cqupt.edu.cn/
npmMirror https://skimdb.npmjs.com/registry/

向verdaccio提交npm 包

1
npm adduser --registry=http://localhost:4873/

输入用户名username, Password和Email完成注册

1
npm login

输入用户名username, Password和Email完成登陆
发布一个test包

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
npm publish

npm notice
npm notice package: test@1.0.0
npm notice === Tarball Contents ===
npm notice 218B package.json
npm notice 68B index.js
npm notice === Tarball Details ===
npm notice name: test
npm notice version: 1.0.0
npm notice package size: 330 B
npm notice unpacked size: 286 B
npm notice shasum: fb6af7b1f50154df28672514d303332837ee36ad
npm notice integrity: sha512-7ibhQs2/jctNE[...]bzYyQhj9k+aUQ==
npm notice total files: 2
npm notice
+ test@1.0.0

孤独,寂静,在两条竹篱笆之中,篱笆上开满了紫色的牵牛花,在每个花蕊上,都落了一只蓝蜻蜓。
——王小波