当前位置:网站首页>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私库的全部内容啦,最重要的是自己亲手实践哈,实践的过程中遇到问题学会思考和面向百度就能不断成长啦~
边栏推荐
- R语言使用yardstick包的conf_mat函数计算多分类(Multiclass)模型在每个交叉验证(或者重采样)的每一折fold上的混淆矩阵、并使用summary输出每个fold的其它详细指标
- Interpretation of hard threshold function [easy to understand]
- 路由基础之OSPF LSA详细讲解
- How to count the status of network sockets?
- CS5268优势替代AG9321MCQ Typec多合一扩展坞方案
- R language builds a binary classification model based on H2O package: using H2O GBM build gradient hoist model GBM, use H2O AUC value of AUC calculation model
- 买卖其实也有风险
- 请问flink mysql cdc 全量读取mysql某个表数据,对原始的mysql数据库有影响吗
- Powerful, easy-to-use, professional editor / notebook software suitable for programmers / software developers, comprehensive evaluation and comprehensive recommendation
- Tencent Li Wei: deeply cultivate "regulatory technology" to escort the steady and long-term development of the digital economy
猜你喜欢

项目部署,一点也不难!
![[brain opening] west tide and going to the world series](/img/b2/444af296e170d19629800b3d4c50fa.jpg)
[brain opening] west tide and going to the world series

晓看天色暮看云,美图欣赏

硬件开发笔记(九): 硬件开发基本流程,制作一个USB转RS232的模块(八):创建asm1117-3.3V封装库并关联原理图元器件

"Analysis of 43 cases of MATLAB neural network": Chapter 40 research on prediction of dynamic neural network time series -- implementation of NARX based on MATLAB

Look at the sky at dawn and the clouds at dusk, and enjoy the beautiful pictures

Based on the open source stream batch integrated data synchronization engine Chunjun data restore DDL parsing module actual combat sharing

Share several tools for designing exquisite circuit diagrams
![leetcode:329. The longest incremental path in the matrix [DFS + cache + no backtracking + elegance]](/img/10/acd162c3adf9d6f14fa5a551dc0d25.png)
leetcode:329. The longest incremental path in the matrix [DFS + cache + no backtracking + elegance]

王兴的无限游戏迎来“终极”一战
随机推荐
Understanding of NAND flash deblocking
数论基础及其代码实现
logstash报错:Cannot reload pipeline, because the existing pipeline is not reloadable
项目部署,一点也不难!
Huawei interview question: Recruitment
快速整明白Redis中的压缩列表到底是个啥
Digital signal processing -- Design of linear phase (Ⅱ, Ⅳ) FIR filter (2)
When Sqlalchemy deletes records with foreign key constraints, the foreign key constraints do not work. What is the solution?
Update a piece of data from the database. Will CDC get two pieces of data with OP fields D and C at the same time? I remember before, only OP was U
華為面試題: 招聘
【邂逅Django】——(二)数据库配置
How can genetic testing help patients fight disease?
使用nvm管理nodejs(把高版本降级为低版本)
Stack-------
Vs code setting Click to open a new file window without overwriting the previous window
Ikvm of toolbox Net project new progress
Tencent always takes epoll, which is annoying
PG基础篇--逻辑结构管理(触发器)
Nc100 converts strings to integers (ATOI)
Fundamentals of number theory and its code implementation