NPM软件包发布到Nexus

NPM软件包发布到Nexus

1.Linux安装nodejs环境

下载地址 https://nodejs.org/en/download/

wget https://nodejs.org/download/release/v14.18.3/node-v14.18.3-linux-x64.tar.gz
tar xf  node-v14.18.3-linux-x64.tar.gz
mkdir -p /usr/software/
mv node-v14.18.3-linux-x64 /usr/software/nodejs
ln -s /usr/software/nodejs/bin/npm   /usr/local/bin
ln -s /usr/software/nodejs/bin/node   /usr/local/bin
node -v
npm -v

2.创建镜像仓库

名称自己定义,这里我定义为npm

在这里插入图片描述

3.添加nexus权限

在Realms菜单中,将npm Bearer Token Realm添加到Active中;
不添加执行npm publish 会报错

  • npm ERR! code ENEEDAUTH
  • npm ERR! need auth This command requires you to be logged in.
  • npm ERR! need auth You need to authorize this machine using npm adduser

在这里插入图片描述

4.设置镜像仓库地址

npm config -g set registry http://x.x.x.x:port/repository/npm/
npm adduser -registry http://xxx.xx.x.x:xxxx/repository/npm
Username: admin
Password: 
Email: (this IS public) xxxx@yyy.com

5.发布单个包

5.1在package.json同级目录

npm publish -registry http://xxx.xx.x.x:xxxx/repository/npm

5.2在package.json 中添加私库地址,然后执行 npm publish

"publishConfig": {
    "registry": "仓库地址"
 },

6.发布tgz包

npm publish -registry=http://xxx.xx.x.x:xxxx/repository/npm  core-util-is-1.0.3.tgz
或
npm publish core-util-is-1.0.3.tgz

7.批量发布npm包到私有仓库

私网环境是无法下载npm包,一般事先要有网络的节点新先进行下载,然后拷贝到到私网服务器上

find . -type f -name "*.tgz"  | sed "s|^\./||" | xargs -I '{}' npm publish {}  2>&1 | tee -a npm.log

有些存在"publishConfig": { "registry": "仓库地址" },被限制了,需要手工维护,在进行上传

cat npm.log |grep ERR
grep ".tgz"  /root/.npm/_logs/*.log |grep 'verbose cli'

以下npm存在仓库地址被固定了

在这里插入图片描述

8.查看nexus的npm仓库

在这里插入图片描述

9.测试

mkdir test && cd test
npm init --yes
npm install vconsole@^3.14.6
npm install base64-js
  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值