npm config

  1. // 设置仓库地址
  2. npm config set registry XXXXX(地址)
  3. // 查看npm当前配置
  4. npm config list

npm adduser [—registry=url] [—scope=@orgname] [—always-auth]

  1. 当前环境添加npm用户
  2. npm adduser
  3. Username: your name
  4. Password: your password
  5. Email: yourEmail[@gmail].com

npm login

切换用户登录

npm logout

npm logout [—registry=] —scope=<@scope>

npm whoami

  1. 查看当前用户信息
  2. 显示当前用户的名称

npm publish

发布当前的资源到npm库
注意:npm库要保持名称的唯一性,如果不唯一则不能上传成功

  1. package.json 中配置需要发布的文件或者文件夹
  2. {
  3. "files": [
  4. "dist",
  5. "lib",
  6. "es"
  7. ]
  8. }

npm unpublish —force

强行删除远程仓库

npm scope

npm官方仓储有两种类型的包,普通包和scope包

普通包特征: - 只能公有,谁都可以下载使用 - 仅可以通过所有者(owner)进行权限控制,如果要允许某个用户修改或发布包,必须将该用户添加到包的所有者列表。添加到包所有者列表的用户具备所有的权限.

scope包特征:
- 包名有两部组成,@scope/name, @后的为scope名,/后的才是具体的包名 - 可以控制公有和私有 - 细化的权限控制,比如可以创建团队,并赋予团队对包只读/修改的权限

npm own(为普通包添加own权限)

npm owner add [<@scope>/] # 将用户添加到包的所有者列表
npm owner rm [<@scope>/] # 从包的所有这列表中删除用户
npm owner ls [<@scope>/] # 列出包的所有者
成为包的所有者的用户,将能够修改元数据(如标记弃用),发布新版本,添加其他用户到包的所有者列表

npm team

npm team create # 创建团队
npm team destroy # 删除团队
npm team add # 添加用户到团队
npm team rm # 从团队中移除用户
npm team ls | 列出团队/成员
npm team edit 用编辑器编辑团队信息

npm access

npm access public [] # 设置包开放
npm access restricted [] # 设置包私有
npm access grant [] # 设置团队对包可以只读/允许修改
npm access revoke [] # 从团队中收回包权限
npm access ls-packages [||] # 列出用户/域/团队能够访问的包
npm access ls-collaborators [ []] # 列出包的权限信息
npm access edit [] # 用编辑器编辑包权限

npm install/i

npm install (with no args, in package dir) # 读取package.json安装
npm install [<@scope>/] # 默认安装标签为latest
npm install [<@scope>/]@ # 指定标签
npm install [<@scope>/]@ # 指定版本
npm install [<@scope>/]@ # 指定版本范围
npm install # 通过tarball文件安装
npm install # 通过tarball文件url链接安装
npm install # 通过git安装包, url格式为://[[:]@][:][:][/][#]
npm install 通过包所在的文件夹安装

npm uninstall/un

npm uninstall [<@scope>/][@]… [-S|—save|-D|—save-dev]

  • -S/—save: 删除包并移除包在package.json的dependencies区的信息
  • -D/—save-dev: 删除包并移除包在package.json的devDependencies区的信息

npm dedupe/ddp

npm dedupe : npm检查包依赖树并清除不要的包

npm dist-tags(常见标签有latest, next, lts等)

npm dist-tag add @ [] # 添加标签
npm dist-tag rm # 移除标签
npm dist-tag ls [] # 列出包所包含的标签

可以在发布和下载包是带上标签(—registry: 发布包到指定仓储)
npm publish # 默认标签latest
npm publish —tag next # 发布next标签
npm install npm # 默认标签latest
npm install npm@next npm install —tag next

  1. npm --- https://registry.npmjs.org/
  2. cnpm --- https://r.cnpmjs.org/
  3. taobao --- https://registry.npm.taobao.org/
  4. nj --- https://registry.nodejitsu.com/
  5. rednpm --- https://registry.mirror.cqupt.edu.cn/
  6. npmMirror --- https://skimdb.npmjs.com/registry/
  7. deunpm --- http://registry.enpmjs.org/

参考:
https://juejin.im/entry/590fcd02a22b9d0058036856