如何上傳發布自己的npm組件包

來源:互聯網
上載者:User

標籤:des   style   blog   http   使用   os   

本文介紹如果上傳自己寫的 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  下則運行

$ vim ~/.npmrc


並編輯這個檔案的內容

registry = http://admin:[email protected]:5984/registry/_design/scratch/_rewrite

前面的 admin:123456 是使用者名稱密碼

STEP2 建立一個測試專案

$ mkdir testmypublish$ cd testmypublish$ vim package.json

把以下內容粘貼進去

{  "name":    "testmypublish",  "version": "0.0.1",  "repository" :  { "type" : "git"  , "url" : "https://github.com/<yourusername>/testmypublish.git"  }}

這邊聲明以下,那個 repository 屬性不寫也可以,但是最好建一個 github 項目然後把地址寫進來,這樣會比較規範。沒有github帳號的朋友就別寫這段了直接寫成

{  "name":    "testmypublish",  "version": "0.0.1"}
就行

STEP3 添加npm使用者

 

$ npm adduserUsername: alexPassword: Email: (this IS public) [email protected]

STEP 4 登陸剛剛建立的使用者

npm login alexUsername: (alex) Password: (or leave unchanged) Email: (this IS public) ([email protected])

問username password email的時候一路斷行符號就好

STEP 5 發布項目 

$ cd testmypublish$ npm publish+ [email protected]

這就發布完成了


用戶端測試

$ npm install testmypublish



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.