npm包发布--私库(二)
nexus添加权限有add申请添加提交到私库的权限全局设置 .npmrcregistry=http://alm.homecredit.cn/nexus/repository/npm-group/_auth=BASIC bWljaGVhbC5tYTpNYWppZTE2IQ==Registry下载私库地址_auth 根据 用户名:密码 通过64位加密获取项目本身的.npm...
npm包的发布–私库(二)
之前讲述过npm包的发布,但是如果上传的地址不是https://www.npmjs.com/,而是公司的nexus私库,那么上传方式与上传到官网是有些不一样的,这里的官网是指https://www.npmjs.com/。
在开始之前,首先需要确定你在nexus中添加权限, 有add申请添加提交到私库的权限,或者私库中某个地址提交代码的权限
尝试直接操作
先按照之前的方式发布,首先登录
npm login
这里我们输入的username password email是公司nexus私库的用户名账号 密码与邮箱
终端报错
npm ERR! Incorrect or missing password.
npm ERR! If you were trying to login, change your password, create an
npm ERR! authentication token or enable two-factor authentication then
npm ERR! that means you likely typed your password in incorrectly.
npm ERR! Please try again, or recover your password at:
npm ERR! https://www.npmjs.com/forgot
npm ERR!
npm ERR! If you were doing some other operation then your saved credentials are
npm ERR! probably out of date. To correct this please try logging in again with:
npm ERR! npm login
我发现它提示的是密码不正确,但是我很肯定使用该账号密码登录了私库,接下来分析发现所谓的密码错误针对的是官网,我要上传的地址根本不是官网,账号密码也不是官网对应账号密码,当然也不可以找官网验证,因此考虑是不是应该设置一下 npm register 源
然后设置源,也即上传地址
npm set register http://xxx.xxx.xxx/nexus/repository/npm-hosted/
然后重新登录,如果你登陆成功以下部分可以不看,如果仍旧不成功,发现仍旧报错,最后查找发现需要安装nrm包,对register源进行管理的包
使用源管理包nrm方式
安装nrm
npm install -g nrm
nrm命令
查看 nrm 源列表
带 * 号即为当前使用的配置
nrm ls
终端
* npm -------- https://registry.npmjs.org/
yarn ------- https://registry.yarnpkg.com/
cnpm ------- http://r.cnpmjs.org/
taobao ----- https://registry.npm.taobao.org/
nj --------- https://registry.nodejitsu.com/
npmMirror -- https://skimdb.npmjs.com/registry/
edunpm ----- http://registry.enpmjs.org/
查看当前使用源
nrm current
终端
npm
添加源
nrm add <名称> <远程地址或私服地址>
例如:nrm add nhost http://xxx.xxx.xxx/nexus/repository/npm-hosted/
终端
add registry nhost success
测试源速度
nrm test <名称>
终端
nhost -- 65ms
切换源
nrm use <名称>
终端
Registry has been set to:http://xxx.xxx.xxx/nexus/repository/npm-hosted/
删除源
nrm del <名称>
此时再次登录,登录成功
直接上传,成功!!!并没有修改package.json文件
如果下载的源不同直接切换源即可
添加项目.npmcr文件方式
设置上传地址
更改上传包的package更改上传包的package.json文件,设置上传私库,在最后添加publishConfig配置,
与name平级
"publishConfig": {
"registry": "http://xxx.xxx.xxx/nexus/repository/npm-hosted/"
}
添加项目级.npmcr文件
添加与pcakge.json同级文件.npmrc
_auth=YWRlbGFpZGUudGlhbjpUamoyMDE5MDQwMw==
_auth后面的内容是 <账号>:<密码> 通过base64 加密获取的
base64 加密方式可以直接在网上搜索一个
添加文件后,该方式直接上传即可,无需登录
npm publish
添加项目与全局.npmcr文件方式
全局设置 .npmrc
npm config set //xxx.xxx.xxx/repository/npm-group/:_authToken NpmToken.73d-91-46-9bf-6d15d2
registry=http://xxx.xxx.xxx/nexus/repository/npm-group/
_auth=BASIC YWRlbGFpZGUudGlhbjpUamoyMDE5MDQwMw==
//xxx.xxx.xxx/nexus/repository/npm-group/:_authToken=NpmToken.87f0-cca-321-371-c59a32
registry下载私库地址
_auth 内容也是根据私库对应的账号与密码: 通过<账号>:<密码> base64加密获取
项目级别的.npmrc文件
registry=http://xxx.xxx.xxx/nexus/repository/npm-group/
_auth=YWRlbGFpZGUudGlhbjpUamoyMDE5MDQwMw==
always-auth=true
email=<私库对应邮箱>
package.json
"publishConfig": {
"registry": "http://xxx.xxx.xxx/nexus/repository/npm-hosted/"
}
操作完成后,该方式直接上传即可,无需登录
npm publish
更多推荐

所有评论(0)