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
|