日常总结 -- verdaccio搭建npm私有仓库

verdaccio搭建npm私有仓库

参考:
verdaccio https://github.com/verdaccio/verdaccio#readme
搭建NPM私有库 https://www.jianshu.com/p/1d0e85d14234
用npm发布包 http://www.cnblogs.com/chengxs/p/7651653.html

安装verdaccio

# 安装verdacio
npm install --global verdaccio
# 启动
verdaccio
# 更改npm配置
npm set registry http://localhost:4873/
# 如果你使用HTTPS, 添加一个适当的CA信息(“null” 的意思从系统获取CA列表)
npm set ca null

浏览 http://localhost:4873/, 这里将列出已提交的本地包(暂时还没有)

服务端

运行verdaccio时, 会建立两个默认的文件(Windows默认路径 C:\Users\Administrator.config\verdaccio): config.yaml和storge,htpasswd在添加用户后被创建

  • config.yaml 用来配置访问权限,代理,文件存储路径等所有配置信息;
  • storge 用来存放NPM包;
  • htpasswd 用来保存用户账户、密码等信息。

封装发布本地包

准备一个文件夹(npm_push_test), 里面包含 入口js(index.js); 最好有一个README.md文件做本地插件包的介绍, 没有也不影响;

# 初始化要封装的包
npm init
# 这里提示输入: 
 #- name:填写个包的名字,默认是这个文件夹的名字(npm有同名的包会报错); 
 #- version:包的版本,默认是1.0.0;
 #- description:要封装的包的简单介绍;
 #- entry point:入口文件,默认是index.js,也可以是其它名字;
 #- test command:测试命令,直接回车;
 #- git repository:这个是git仓库地址,如果你的包是先放到github上或者其他git仓库里,这时候你的文件夹里面会存在一个隐藏的.git目录,npm会读到这个目录作为这一项的默认值。如果没有的话,直接回车继续;
 #- keyword:作为这个包的索引的关键字;
 #- author:作者名或账号;
 #- license:许可证, 没有就直接回车;

之后会生成一个package.json文件;
package.json

{
  "name": "local_npm_push_test",
  "version": "1.0.0",
  "description": "npmjs package test",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "npm_push_test"
  ],
  "author": "surliya",
  "license": "ISC"
}

发布包
# 查看npm包镜像
npm config get registry
# 更改npm包镜像 (最后的最后再改回来 https://registry.npm.taobao.org)
npm config set registry http://localhost:4873/
# 注册用户(在要提交的包文件夹下注册, 这里用有用户名,密码,邮箱的输入提示)
npm adduser --registry http://localhost:4873/
# 或者 npm login
# 发布
npm publish --registry http://localhost:4873/  
# 或 npm publish
# 下载
npm install local_npm_push_test

刷新 http://localhost:4873/

注:
1.发布新版本时需要改package.json文件里的版本号;
2.需要覆盖公共包时, 只需在发布时更改版本号即可;
3. npm安装更新出现 npm WARN deprecated socks@1.1.10: If using 2.x branch, please upgrade to at least 2.1.6 to avoid a serious bug with socket data flow and an import issue introduced in 2.1.0 错误, 解决方案: 降低版本 npm install npm@4.6.1 -g

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值