项目中需要自己搭建一个npm的私服,用来发布一些项目中公共的小组件,自己在本地使用win10的Docker Desktop容器搭建了个sinopia,自己测试使用;
这个是第一步也是必须的,网上好多教程,这里不介绍了
这里用到了keyvanfatehi/sinopia:latest,直接pull就行
docker pull keyvanfatehi/sinopia
version: '2'
services:
sinopia:
image: "keyvanfatehi/sinopia:latest"
container_name: sinopia
restart: always
volumes:
- "//d/workspace/docker_images/sinopia/data/config.yaml:/opt/sinopia/config.yaml"
- "//d/workspace/docker_images/sinopia/data/storage:/opt/sinopia/storage"
ports:
- "4873:4873"
其中,将配置文件config.ymal和storage挂载了出来,把配置挂载出来是为了改起来方便
进入和docker-compose.yml同一级目录,执行下面命令启动就可以了。
docker-compose up -d
访问http://localhost:4873/
#
# 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
#npm包存放的路径
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 #默认为1000
# a list of other known repositories we can talk to
uplinks:
npmjs:
url: http://registry.npm.taobao.org/ #代理镜像源,默认为npm的官网,由于需要安全上网,修改 url 让sinopia使用 淘宝的npm镜像地址
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
#如其名,这里的值是对应于上面的 uplinks
proxy: npmjs
# log settings
logs:
- {type: stdout, format: pretty, level: http}
#- {type: file, path: sinopia.log, level: info}
listen:
- 0.0.0.0:4873 #默认没有,只能在本机访问,添加后可以通过外网访问
npm set registry http://localhost:4873
npm adduser --registry http://localhost:4873
先登录
npm login
然后进入自己要上传的npm组件代码的根目录,执行npm publish
npm publish
结果可以看到如下图
登录sinopia,就可以看到自己发布的包了