前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用Sinopia搭建私有npm仓库

使用Sinopia搭建私有npm仓库

作者头像
kongxx
发布2018-05-14 11:58:53
1K0
发布2018-05-14 11:58:53
举报

在用npm装包的时候,每次都要下载一大堆,慢且不说,npm还老被墙,所以就想到在公司内部搭建npm仓库镜像。大概看了几个,觉得Sinopia最简单也好用,所以就使用Sinopia搭建仓库吧。

安装

代码语言:javascript
复制
sudo npm install -g sinopia

配置与运行

安装完成后,暂时不知道配置文件在哪里,可以先运行一下 sinopia,比如:

代码语言:javascript
复制
$ sinopia
 warn  --- config file  - /home/<user>/.config/sinopia/config.yaml
 warn  --- http address - http://localhost:4873/

从上面命令输出可以看到配置文件路径:/home/<user>/.config/sinopia/config.yaml

下面修改配置文件,在最后加上一行 “listen: 0.0.0.0:4873”,目的是为了可以从别的机器上也能访问 sinopia 仓库。

代码语言:javascript
复制
#
# 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: /home/jhadmin/.local/share/sinopia/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: info}
  #- {type: file, path: sinopia.log, level: info}

listen: 0.0.0.0:4873

修改完成后再次启动 Sinopia 服务,如下:

代码语言:javascript
复制
$ sinopia
 warn  --- config file  - /home/<user>/.config/sinopia/config.yaml
 warn  --- http address - http://0.0.0.0:4873/

使用

私有仓库已经有了,下面来看看怎么使用,这里我们使用了nrm来管理私有仓库。(可以参考我的前一篇博客)

添加私有仓库

代码语言:javascript
复制
$ nrm add mynpm http://192.168.0.123:4873

使用私有仓库

代码语言:javascript
复制
$ nrm use mynpm

测试私有仓库

代码语言:javascript
复制
$ mkdir test
$ cd test
$ npm install webpack # 第一次安装比较慢
...

$ rm -rf webpack
$ npm install webpack # 第二次安装就比较快了
...
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017.06.16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 安装
  • 配置与运行
  • 使用
    • 添加私有仓库
      • 使用私有仓库
        • 测试私有仓库
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档