如何上传发布自己的npm组件包

如何上传发布自己的npm组件包

2015年03月13日 00:57:55

阅读数:7235

本文介绍如果上传自己写的 npm 组件包到 npm私库上。当你 写好了自己的一个npm的组件想共享上去给别人或者给公司的同事使用的时候,你可以把你的npm组件发布上去 (publish)。不过npm的全局库估计你是上传不上去的,要经过审核,但是你可以上传到你自己公司的私库,搭建私库的教程可以参见 http://blog.csdn.net/nsrainbow/article/details/35989657

 

 前提条件:

 

  1. 你已经建好了一个公司的私库,这个私库地址是 http://localhost:5984/registry/_design/scratch/_rewrite
  2. 你为这个私库设置了用户名 admin 密码 123456 

 

STEP1 修改.npmrc

在自己的home目录下看看有没有.npmrc 这个文件存在,如果没有的话增加一个,如果你是在 linux  下则运行

 

[plain] view plaincopy在CODE上查看代码片派生到我的代码片

  1. $ vim ~/.npmrc  

 

 

并编辑这个文件的内容

 

[plain] view plaincopy在CODE上查看代码片派生到我的代码片

  1. registry = http://admin:123456@localhost:5984/registry/_design/scratch/_rewrite  


前面的 admin:123456 是用户名密码

 

STEP2 建立一个测试项目

 

[plain] view plaincopy在CODE上查看代码片派生到我的代码片

  1. $ mkdir testmypublish  
  2. $ cd testmypublish  
  3. $ vim package.json  


把以下内容粘贴进去

 

 

[plain] view plaincopy在CODE上查看代码片派生到我的代码片

  1. {  
  2.   "name":    "testmypublish",  
  3.   "version": "0.0.1",  
  4.   "repository" :  
  5.   { "type" : "git"  
  6.   , "url" : "https://github.com/<yourusername>/testmypublish.git"  
  7.   }  
  8. }  


这边声明以下,那个 repository 属性不写也可以,但是最好建一个 github 项目然后把地址写进来,这样会比较规范。没有github账号的朋友就别写这段了直接写成

 

 

[plain] view plaincopy在CODE上查看代码片派生到我的代码片

  1. {  
  2.   "name":    "testmypublish",  
  3.   "version": "0.0.1"  
  4. }  

就行

 

STEP3 添加npm用户

 

[plain] view plaincopy在CODE上查看代码片派生到我的代码片

  1. $ npm adduser  
  2. Username: alex  
  3. Password:   
  4. Email: (this IS public) Alex.Yang@ehealth.com  

 

 

STEP 4 登陆刚刚建立的用户

 

[plain] view plaincopy在CODE上查看代码片派生到我的代码片

  1. npm login  
  2. Username: (alex)   
  3. Password: (or leave unchanged)   
  4. Email: (this IS public) (Alex.Yang@ehealth.com)  


问username password email的时候一路回车就好

 

STEP 5 发布项目 

 

[plain] view plaincopy在CODE上查看代码片派生到我的代码片

  1. $ cd testmypublish  
  2. $ npm publish  
  3. + testmypublish@0.0.1  


这就发布完成了

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值