有时候需要将自己写的一些前端项目打包发布到公司内部的nexus仓库中。
Blob store
最好选择为 npm 专属的Blob Stores
新建Allow redeploy
否则在后面上传的时候会报错
npm ERR! code E400
npm ERR! 400 Bad Request - PUT http://xxx.xxx.xxx.xxx:xxxx/repository/npm-hosted/demo-test - Repository does not allow updating assets: npm-hosted
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/wjy/.npm/_logs/2019-12-18T03_09_27_631Z-debug.log
重新查看配置如下:
Create repository
创建在 Repositories 列表中选择刚刚建的 npm-hosted ,点击copy
在npm 中配置仓库地址,执行命令:
npm config set registry 仓库地址
执行命令:
npm config list
即配置正确。
在Realms
菜单中,将npm Bearer Token Realm
添加到Active
中。
移动后的结果:
然后点击Save
按钮保存
这里一定要移动,不然会报错。
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 ERR! /Users/wjy/.npm/_logs/2019-12-18T02_29_24_122Z-debug.log
1.新建一个目录 demo-test
,并切换到其中
mkdir demo-test && cd demo-test
npm init
然后一路回车,最后键入y
即可
npm adduser -registry 仓库地址
npm adduser -registry http://xxx.xx.x.x:xxxx/repository/npm-hosted/
Username: admin
Password:
Email: (this IS public) [email protected]
Logged in as admin on http://xxx.xx.x.x:xxxx/repository/npm-hosted/.
上传的包一定要确保根目录下有
package.json
,否则会报错。
执行命令:
npm publish -registry 仓库地址
demo-test npm publish -registry http://xx.xx.xx.xx:xxx/repository/npm-hosted/
npm notice
npm notice [email protected]
npm notice === Tarball Contents ===
npm notice 348B package.json
npm notice === Tarball Details ===
npm notice name: demo-test
npm notice version: 1.0.0
npm notice package size: 320 B
npm notice unpacked size: 348 B
npm notice shasum: c897041e0aa1cbf68734be9e4058e39490de8eb3
npm notice integrity: sha512-Seb61XX1ronMM[...]ioQBdXs2fEW+Q==
npm notice total files: 1
npm notice
+ [email protected]
➜ demo-test
此时即上传成功。
在package.json 中添加
"publishConfig": {
"registry": "仓库地址"
},
即:
然后执行:
npm publish