搭建npm私服

2017-09-27  本文已影响0人  SevenLonely

1.安装npm私服服务github地址

npm install -g sinopia  

2.启动sinopia

sinopia
// sinopia 的配置文件所在路径
warn  --- config file - /root/.config/sinopia/htpassw

//sinopia 服务的域名和端口号
warn  --- http address - http://localhost:4873/

3.守护进程

1.安装PM2

npm install -g pm2

2.通过 PM2 启动 sinopia

pm2 start `which sinopia`

4.修改sinopia配置文件

#
# 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  #npm包存放的路径

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: -1  #默认为1000,改为-1,禁止注册

# 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  #表示哪一类用户可以对匹配的项目进行安装 【$all 表示所有人都可以执行对应的操作,$authenticated 表示只有通过验证的人可以执行对应操作,$anonymous 表示只有匿名者可以进行对应操作(通常无用)】
    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  #如其名,这里的值是对应于 uplinks

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

# you can specify listen address (or simply a port) 
listen: 0.0.0.0:4873  #默认没有,只能在本机访问,添加后可以通过外网访问

(原文参考:https://segmentfault.com/a/1190000005790827

5.添加用户

npm adduser

6.发布包

// 每次发布之前要用命令登录
npm login
//初始化包
npm init
//发布包
npm publish

可以在http://localhost:4873/ 查看包的详情

上一篇 下一篇

猜你喜欢

热点阅读