搭建npm服务器
1.安装sinopia
npm install sinopia -g
复制代码
安装完成后执行:
sinopia
复制代码
输出:
warn --- config file - C:\Users\Administrator\.config\sinopia\config.yaml
warn --- http address - http://localhost:4873/
复制代码
执行成功,打开 http://localhost:4873/ 可以看到类似npm官网的界面,此时npm私服搭建成功!
2.node进程守护工具:pm2。
这里不赘述,可参考:segmentfault.com/a/119000000…
3.sinopia配置文件
step1中控制台输出的配置文件: C:\Users\Administrator.config\sinopia\config.yaml 初始配置:
#
# 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/rlidwka/sinopia/tree/master/conf
#
# path to a directory with all packages
storage: ./storage
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
'*':
# 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
# log settings
logs:
- {type: stdout, format: pretty, level: http}
#- {type: file, path: sinopia.log, level: info}
复制代码
客户端使用
1.创建用户
npm adduser --registry http://localhost:4873/
复制代码
按提示依次输入用户名、密码、邮箱。
2.发布包
npm publish --registry http://localhost:4873/
复制代码
3.安装包(test为包名)
npm install --registry http://localhost:4873/ test --save
复制代码