如何用Verdaccio搭建一个企业级私有Npm库
当公司项目做得比较多的何用时候,我们就会自己孵化出一套内部的建个级私业务组件库,这些企业级的企业组件我们并不想上传到公共的npm仓库,这个时候企业级私有npm就比较重要了,何用Verdaccio可以非常简单,建个级私且零配置的企业帮我们搭建企业级私有npm库
官网地址:https://verdaccio.org/
// 目前github的star是13K
github地址:https://github.com/verdaccio/verdaccio
安装// 全局安装
npm install -g verdaccio
// 安装完verdaccio后
// 命令行执行verdaccio,我们看到如下结果
verdaccio
verdaccio结果
从上面的何用截图我们看到verdaccio已经零配置安装成功了,并且输出了它的建个级私配置文件位置、启动的站群服务器企业服务地址等信息,默认是何用在4873端口启动,我们在浏览器中输入http://localhost:4873,建个级私就可以看到默认启动界面。企业
启动界面
配置修改我们打开
/Users/storm/.config/verdaccio/config.yaml目录下的何用文件,以下是建个级私我整理的默认的配置
storage: ./storage
plugins: ./plugins
web:
title: Verdaccio
auth:
htpasswd:
file: ./htpasswd
uplinks:
npmjs:
url: https://registry.npmjs.org/
packages:
@*/*:
access: $all
publish: $authenticated
unpublish: $authenticated
proxy: npmjs
**:
access: $all
publish: $authenticated
unpublish: $authenticated
proxy: npmjs
server:
keepAliveTimeout: 60
middlewares:
audit:
enabled: true
logs:
- { type: stdout, format: pretty, level: http }
我们主要修改packages这个属性,目前是企业所有人都可以访问,然后注册过的人可以上传npm包的,$all代表没有任何限制,云服务器提供商$authenticated代表注册过的人。
packages:
@*/*:
access: $authenticated
publish: $authenticated
unpublish: $authenticated
proxy: npmjs
**:
access: $authenticated
publish: $authenticated
unpublish: $authenticated
proxy: npmjs
通过以上的配置,这样就只有团队注册过的人,才有权限访问了。
基本使用// 注册用户,按操作提示,一步一步完成
npm adduser --registry http://localhost:4873/
// 指定本地npm的源为私有库
npm set registry http://localhost:4873/
// 或者安装依赖的时候,指定私有库安装
npm install --registry http://localhost:4873
后面的发布npm包,登录这些的操作就和公网npm一样的操作流程。b2b信息网