标签搜索

目 录CONTENT

文章目录

npm配置nexus私库实现拉去推送

陈铭
2021-07-12 / 0 评论 / 0 点赞 / 246 阅读 / 449 字 / 正在检测是否收录...

手动模式

每次推拉都需要手动登录,比较麻烦

配置远程库

设置npm拉取的组url

npm config set registry=http://172.28.118.19:8100/repository/rcd_npm_group/

登录远程库

npm login

拉取

npm install <PACKEAGENAME>@<VERSION>

推送

创建一个nodejs的模块

初始化package.json,可以使用npm init

{
    "name": "example",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "author": "",
    "license": "MIT"
}

创建用户,这一步必须的,不然推送会出现认证错误。

推送一般推送至组下的host私库,用户创建也对应于host库

npm adduser --registry=http://xxx.xxx.xxx.xxx:8100/repository/rcd_npm_local/

推送npm包

npm publish --registry=http://xxx.xxx.xxx.xxx:8100/repository/rcd_npm_local/

自动模式

可以将登录验证的逻辑写死在npm的配置中

配置npm config

npm的用户级配置文件在 $HOME/.npmrc
npm配置的优先级是:命令行–para > 用户级.npmrc > 默认.npmrc
文件配置好登录相关的信息

; 配置一个库,那么npm无论拉取还是推送都会使用这个(; 开头是.npmrc的注释形式)
registry=<nexus_local_repo_url>
; nexus上查看
email=xxx
always-auth=true
; username:password 的 base64形式
; 执行 echo -n "admin:admin" | openssl base64 进行base64编码
_auth="xxxx"

推送

初始化package.json,和上面一样,再推送npm包

# 不指定registry,默认使用.npmrc内的registry
npm publish --registry=<nexus_local_repo_url>

注意:推送的库一定是hosted库,如果.npmrc内的registry不是hosted的库,请指定--registry;或者在piblish前执行:
npm config set registry=<nexus_local_repo_url>

拉取

npm install <PACKEAGENAME>@<VERSION>
0

评论区