当前位置:网站首页>nexus搭建npm依赖私库
nexus搭建npm依赖私库
2022-07-01 12:44:00 【一个运维小青年】
nexus搭建npm依赖私库
npm仓库介绍
3.2.1.默认仓库说明
npm-proxy:可以代理npmjs和淘宝镜像
npm-hosted:用于上传、自定义和个人开发的npm组件
npm-public:仓库分组,把几个仓库组组合在一起使用。
3.2.1.仓库类型
Group:这是一个仓库聚合的概念,用户仓库地址选择Group的地址,即可访问Group中配置的,用于方便开发人员自己设定的仓库。maven-public就是一个Group类型的仓库,内部设置了多个仓库,访问顺序取决于配置顺序,3.x默Releases,Snapshots, Central,当然你也可以自己设置。
Hosted:私有仓库,内部项目的发布仓库,专门用来存储我们自己生成的jar文件
3rd party:未发布到公网的第三方jar (3.x去除了)
Snapshots:本地项目的快照仓库
Releases: 本地项目发布的正式版本
Proxy:代理类型,从远程中央仓库中寻找数据的仓库(可以点击对应的仓库的Configuration页签下Remote Storage属性的值即被代理的远程仓库的路径),如可配置阿里云maven仓库
Central:中央仓库
Apache Snapshots:Apache专用快照仓库(3.x去除了)
点击左侧菜单栏Repositories,我们可以看到很多已经配置好的仓库,一般只使用开源jar就够用了,如果需要建立自定义仓库,点击Create repository创建新的仓库

首先我们要创建几个常用的代理源,用于常用开源npm模块的拉取。
骤依次添加以下代理源
taobao
https://registry.npm.taobao.org/
NPM-npmjs
https://registry.npmjs.org

添加代理(Cache统一设置为200天 288000)

设置maven-public
将这些代理加入Group,最好将默认的maven库放到最底下,这里可以忽略

创建npm-hosted ,用于发布个人开发的npm组件。



创建npm-public ,用于把几个仓库组组合在一起公开连接使用。



修改本地Npm连接源
注释:这个是我个人的私服地址,请大家以实际情况进行更改
http://192.168.2.202:8081/
打开Repositories
找到创建的分组npm-public,点击Copy,复制连接源地址

在本地运行以下命令,修改npm仓库源
npm config set registry http://192.168.2.202:8081/repository/npm-public/

发布自己的npm组件到私服
登录私服
复制自己的私服地址
在本地命令控制台,输入以下命令,登录私服
npm login –registry=http://192.168.2.202:8081/repository/npm-hosted/

发布npm组件
要发布的模块,必须保证在根目录下有package.json文件,否则会报错。
npm publish –registry=http://192.168.2.202:8081/repository/npm-hosted/
发布报错
可能是因为我登陆的库是组,不是开发库所以上传报错,从新登陆
npm login –registry=http://192.168.2.202:8081/repository/npm-hosted/
npm ERR! code E401
npm ERR! Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"
npm ERR! A complete log of this run can be found in:

解决办法
终端里输入 npm config list 来获取npm的配置
找到userconfig一项
打开 .npmrc文件。
一般在最后一项。
把所有的私有仓库的地址和NpmToken删除,然后重新yarn或者npm install即可。
缓存依赖包
点击仓库右边的copy按钮复制源地址,然后在本地环境中设置该源地址,npm config set registry=http://xx/repository/group-npm/,切换后执行npm i,install成功后,在nexus的代理仓库中即可看到项目的缓存

- 发布
- 登陆
通过npm login --registry=xx(注意是本地仓库地址) - 发布
通过npm publish --registry=xx(注意是本地仓库地址)

push成功后,我们就可以在hosted仓库看到我们刚刚提交的包啦~

- push失败的话,需要在nexus realms中激活npm bearer token

免去登陆
经常发布的小伙伴可通过npm config edit修改config文件,将以下代码复制到config文件中,免去登陆
registry=http://xx/repository/npm-all/
save-prefix=~
always-auth=true
_auth=YWRtaW46MTIzMTIz
email=[email protected]
- 以上_auth=后面是密码的base64编码,可新建a文本执行
certutil /encode a.txt b.txt输出到b文本,复制b文本的内功即可,也可以通过网上的在线工具实现啦~
ll/
save-prefix=~
always-auth=true
_auth=YWRtaW46MTIzMTIz
[email protected]
1. 以上_auth=后面是密码的base64编码,可新建a文本执行`certutil /encode a.txt b.txt`输出到b文本,复制b文本的内功即可,也可以通过网上的在线工具实现啦~
以上就是nexus3搭建npm私库的全部内容啦,最重要的是自己亲手实践哈,实践的过程中遇到问题学会思考和面向百度就能不断成长啦~
边栏推荐
- 腾讯安全联合毕马威发布监管科技白皮书,解析“3+3”热点应用场景
- Wechat applet - 80 practical examples of wechat applet projects
- GID: open vision proposes a comprehensive detection model knowledge distillation | CVPR 2021
- Router.use() requires a middleware function but got a Object
- Operations related to sequence table
- Tencent always takes epoll, which is annoying
- 微信小程序 – 80个实用的微信小程序项目实例
- Tencent security and KPMG released a regulatory technology white paper to analyze the "3+3" hot application scenarios
- 腾讯总考epoll, 很烦
- leetcode:329. 矩阵中的最长递增路径【dfs + cache + 无需回溯 + 优雅】
猜你喜欢

Stack-------

Redis exploration: cache breakdown, cache avalanche, cache penetration
![[today in history] July 1: the father of time sharing system was born; Alipay launched barcode payment; The first TV advertisement in the world](/img/41/76687ea13e1722654b235f2cfa66ce.png)
[today in history] July 1: the father of time sharing system was born; Alipay launched barcode payment; The first TV advertisement in the world

Queue operation---

redis探索之缓存击穿、缓存雪崩、缓存穿透

leetcode:329. 矩阵中的最长递增路径【dfs + cache + 无需回溯 + 优雅】

Fundamentals of number theory and its code implementation

be based on. NETCORE development blog project starblog - (13) add friendship link function

How can genetic testing help patients fight disease?
![[encounter Django] - (II) database configuration](/img/13/9512c1e03349092874055771c3433d.png)
[encounter Django] - (II) database configuration
随机推荐
Fundamentals of number theory and its code implementation
Has anyone ever encountered this situation? When Oracle logminer is synchronized, the value of CLOB field is lost
【邂逅Django】——(二)数据库配置
Understanding of NAND flash deblocking
运行Powershell脚本提示“因为在此系统上禁止运行脚本”解决办法
买卖其实也有风险
腾讯总考epoll, 很烦
leetcode:329. 矩阵中的最长递增路径【dfs + cache + 无需回溯 + 优雅】
Eurake分区理解
【开发大杀器】之Idea
系统测试UI测试总结与问题(面试)
華為面試題: 招聘
When Sqlalchemy deletes records with foreign key constraints, the foreign key constraints do not work. What is the solution?
Question d'entrevue de Huawei: recrutement
有人碰到过这种情况吗,oracle logminer 同步的时候,clob字段的值丢失
Topic 1004: the story of cows (recursion)
The difference between memcpy and strcpy
There are still many things to be done in the second half of the year
redis探索之缓存一致性
Double linked list related operations