NPM 私有仓库的搭建

为什么搭建私有仓库

balabala,当然是有需求的时候嘛

搭建流程

介绍和安装verdaccio

备注:

程序启动后,配置文件为/home/work/.config/verdaccio/config.yaml

密码文件所在位置:/home/work/.config/verdaccio/htpasswd

日志文件所在文职:/home/work/verdaccio.log

推荐博客1

官方详细文档verdaccio

  1. Nodejs环境全局安装(root)

    npm install –g verdaccio
  2. pm2 运行程序,注意请切换成普通用户work,不需要root

    网址访问 http://localhost:4873

    pm2 start verdaccio
  3. 修改配置文件,配置文件如下,
    参照默认文件修改内容如下

    1. max_users: -1, 限制用户自行注册
    2. logs 日记存储方式为文件
    3. title 修改为公司名称
    4. 修改packages的访问,发布,取消发布的权限,都改为需要登录的权限,初步限制仅公司内部认证过的账户可访问(access: $authenticated,publish: $authenticated,unpublish: $authenticated,proxy: npmjs)
    5. 后期需要的话,可针对不同的仓库配置不同的人员username权限,有开发能力的团队,可自行定制插件中间件,比如限制IP和用户名访问

自定义UI界面

从官方ui主题仓库fork到个人帐号,然后克隆到本地开始进行自定义修改

现在去 github fork?

自定义界面后需要发布版本到npm中,根据配置文件的theme设定重启后会自定应用

从官方仓库中fock出来,修改搜索关键字favicon, title, logo等,footer和header也可以修改一下

修改package.json中的name属性,修改为 verdaccio-theme-****

安装依赖,打包,等录npm,发布到npm仓库(可发布到共有npm,也可以发布到刚刚新起的npm私有仓库服务)

npm install && npm run build && npm login && npm publish
npm i verdaccio-theme-**** -g

服务端安装刚刚发布的主题包(root, 全局安装,因为verdaccio是动态加载插件)

最后在配置文件中修改主题配置

theme:
****:
a:b
su work
pm2 restart verdaccio 重启服务生效

刷新页面吧亲。不知道为什么,仅写theme: ****或者换行不生效,反正我也不懂,能用就行

添加用户

点击去创建htpasswd密码文件网址

去网站生成密码,然后将密码添加到服务端密码文件中,记得重启服务

默认配置

#
# 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/verdaccio/verdaccio/tree/master/conf
# # path to a directory with all packages
storage: ./storage
# path to a directory with plugins to include
plugins: ./plugins web:
title: Qianjunet npm repo
# comment out to disable gravatar support
# gravatar: false
# by default packages are ordercer ascendant (asc|desc)
# sort_packages: asc 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 # a list of other known repositories we can talk to
uplinks:
npmjs:
url: https://registry.npmjs.org/ packages:
'@*/*':
# scoped packages
# access: $all
access: $authenticated
publish: $authenticated
unpublish: $authenticated
proxy: npmjs '**':
# 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
access: $authenticated # allow all known users to publish/publish packages
# (anyone can register by default, remember?)
publish: $authenticated
unpublish: $authenticated # if package is not available locally, proxy requests to 'npmjs' registry
proxy: npmjs # You can specify HTTP/1.1 server keep alive timeout in seconds for incoming connections.
# A value of 0 makes the http server behave similarly to Node.js versions prior to 8.0.0, which did not have a keep-alive timeout.
# WORKAROUND: Through given configuration you can workaround following issue https://github.com/verdaccio/verdaccio/issues/301. Set to 0 in case 60 is not enough.
server:
keepAliveTimeout: 60 middlewares:
audit:
enabled: true # log settings
logs:
#- { type: stdout, format: pretty, level: http }
- {type: file, path: ./verdaccio.log, level: info}
#experiments:
# # support for npm token command
# token: false

配置nginx, 将请求转发到4873服务

server {
listen 80;
server_name npm.**********.com; location / {
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://127.0.0.1:4873$request_uri;
proxy_redirect off;
}
}

如何使用?nrm

  • npm i -g nrm

  • 查看当前所有npm的镜像源

    nrm ls
  • 使用淘宝源

    1
    nrm use taobao
  • 添加我们自定义的私有仓库的源

    1
    nrm add ******** http://npm.*****.com
  • 使用自定义的源

    1
    nrm use ********
  • 添加错误后,可删除源

    1
    nrm del *****
  • 切换到自定义npm源后,使用npm登录

    1
    2
    3
    4
    5
    6
    nrm use ******
    npm login
    input username:
    input password:
    input public email:
    输入相关信息后登录成功,登录成功即可使用npm install some-package-name

发布package

1
2
3
4
5
npm init
code .......
build .....
npm login
npm publish

最终详细配置,还是得看官网,虽然官网的描述很不好懂,而且不全,但是比本篇记录要全,毕竟这个只是小哥哥看完文档,实际操作后的随笔而已

TODO: 待对接npm的用户信息到https://gitlab.*****.com

NPM 私有仓库的搭建的更多相关文章

  1. ndoe.js 和npm私有仓库的搭建

    下载nodejs的压缩包 网址:https://nodejs.org/en/ 下载以tar.xz结尾的包例如:node-v8.9.4-linux-x64.tar.xz 上传包到制定的目录 可以用lrz ...

  2. 使用verdaccio 搭建npm私有仓库

    使用verdaccio 搭建npm私有仓库 1. 为什么要搭建私有的npm仓库?    随着公司的业务越来越复杂,项目迭代速度也越来越快,那么项目间的常用的业务代码共享变得非常之有必要.但是对于公司的 ...

  3. docker学习------docker私有仓库的搭建

    192.168.138.102:23451.私有仓库的搭建(docker pull registry),拉取最新的镜像 2.查看拉取的仓库镜像(docker images) 3.启用registry镜 ...

  4. docker 私有仓库简易搭建

    概要 本地私有仓库 局域网私有仓库 总结 概要 docker hub 使用非常方便,而且上面有大量的镜像可以使用. 但是,每次都远程下载镜像速度非常慢,如果能在本地做一个 docker 的仓库,多人协 ...

  5. Git 安装及用法 github 代码发布 gitlab私有仓库的搭建

    版本控制是一种记录一个或若干文件内容变化,以便将来查阅特定版本修订情况的系统. 这个版本控制软件,有 svn还有git,是一个工具. git是由linux的作者开发的 git是一个分布式版本控制系统 ...

  6. 使用verdaccio+docker搭建npm私有仓库以及使用

    公司内部前端组件或库的共享等,搭建一个npm私有库就很方便,现在中大型公司也基本都有自己的npm私有库,这篇文章,和大家一起共同搭建一个npm私有库,共同学习 前置条件 一台电脑 可以联网 一.安装d ...

  7. npm私有仓库 配置verdaccio在docker环境

    前端开发过程中,少不了自己封装一些通用的包,但又不想放在公共的平台,所以搭建一个npm私有的仓库是很有必要的. 在这里简单介绍如何使用 verdoccio 在docker环境下的配置.verdocci ...

  8. Docker私有仓库Registry 搭建

    1. 关于Registry 官方的Docker hub是一个用于管理公共镜像的好地方,我们可以在上面找到我们想要的镜像,也可以把我们自己的镜像推送上去.但是,有时候,我们的使用场景需要我们拥有一个私有 ...

  9. 基于IP的docker private registry 私有仓库的搭建

    鉴于国内的网络环境,如果公司内部大量使用docker,镜像上传下载将是个非常耗时的工作,搭建一个私有仓库可以很好的解决自有镜像的存储,如果你在私有网络,不能使用域名的话,那么本文可以作为一个很好的例子 ...

随机推荐

  1. Python学习-第三节part1: 关于函数

    一 为何要用函数之不用函数的问题 #1.代码的组织结构不清晰,可读性差 #2.遇到重复的功能只能重复编写实现代码,代码冗余 #3.功能需要扩展时,需要找出所有实现该功能的地方修改之,无法统一管理且维护 ...

  2. UITextFiled-集合目录

    键盘弹起遮挡输入输入框(UITextFiled或者UITextView)                   对于键盘弹起遮挡输入框的问题以前也想过解决办法比如:监听系统键盘弹出通知.根据每个控件所在 ...

  3. Oracle给权限和同义词

    在同一个DB下,用户A创建了一个Table(student),用户B无法访问.如果B想要访问,就需要A赋予B权限. 登录用户A执行下面语句: GRANT SELECT, INSERT, UPDATE, ...

  4. SQL Server中STATISTICS IO物理读和逻辑读的误区

    SQL Server中STATISTICS IO物理读和逻辑读的误区 大家知道,SQL Server中可以利用下面命令查看某个语句读写IO的情况 SET STATISTICS IO ON 那么这个命令 ...

  5. 001_manifest.json手册

    manifest.json 是一个 JSON 格式的文件,是每个 WebExtension必须包含的唯一文件. 使用manifest.json,您可以指定扩展名的基本元数据,如名称和版本,还可以指定扩 ...

  6. 《Three.js 入门指南》3.1.1 - 基本几何形状 -圆环结(TorusKnotGeometry)

    3.1 基本几何形状 圆环结(TorusKnotGeometry) 构造函数 THREE.TorusKnotGeometry(radius, tube, radialSegments, tubular ...

  7. 《Three.js 入门指南》3.1.1 - 基本几何形状 -圆形(CircleGeometry)

    3.1 基本几何形状 圆形(CircleGeometry) 说明: 可以创建圆形或者扇形 构造函数: THREE.CircleGeometry(radius, segments, thetaStart ...

  8. Vmware安装CentOs7.4

    转载https://blog.csdn.net/qq_42545206/article/details/90301472

  9. 1068 Find More Coins (30分)(dp)

    Eva loves to collect coins from all over the universe, including some other planets like Mars. One d ...

  10. 微信小程序--分享功能

    微信小程序--分享功能 微信小程序前段时间开放了小程序右上角的分享功能, 可以分享任意一个页面到好友或者群聊, 但是不能分享到朋友圈 这里有微信开发文档链接:点击跳转到微信分享功能API 入口方法: ...