npm包的發佈與刪除

1. 註冊npm帳號

打開網站:https://www.npmjs.com/,點擊頁面右上角sign up打開註冊頁面:
注意: Full Name、Password和Public Email 註冊之後能夠修改,Username註冊後不可修改。
註冊後須要去郵箱中確認一下。
圖片描述html

1.1 修改npm用戶的默認頭像

npm 網站使用Gravatar頭像庫。
註冊好後,若是想修改默認頭像:vue

  1. 點擊頁面右上角頭像-> Profile Settings,進入我的設置頁面:
  2. 點擊頭像下面的Change Your Gravatar進入 Gravatar網站,若是沒有帳號請註冊一個帳號。
  3. https://en.gravatar.com/ 中選擇My Gravatars
  4. 添加郵箱: 點擊Add email address,輸入註冊npm帳號的郵箱,而後點擊Add.
  5. 添加頭像圖片:點擊Add a new image,若是圖片在電腦上那麼選擇Upload new,選擇一張圖片,點擊Next,修剪一下圖片,點擊Crop Image,選擇一個圖片級別,G全部人都能看,而後點擊Set Rating, 而後點擊Do not use this image yet.
  6. 給郵箱添加頭像:點擊一下郵箱,而後點擊須要的頭像,而後會出現一個彈窗,點擊Confirm,稍等一會便可完成。
  7. npm網站用戶頭像同步須要稍等一會才能看見。

2. 電腦本地npm登錄

  1. 打開終端輸入命令:npm adduser,依次輸入UsernamePasswordEmail,用戶名、密碼、郵箱都是在npm上註冊的。node

    ~ npm adduser
     
    npm http request → POST https://registry.npmjs.org/-/v1/login
    npm http 401 ← Unauthorized (https://registry.npmjs.org/-/v1/login)
    Username: dd
    Password:
    Email: (this IS public) dd@163.com
    npm http request → PUT https://registry.npmjs.org/-/user/org.couchdb.user:dd
    npm http 201 ← Created (https://registry.npmjs.org/-/user/org.couchdb.user:dd)
    Logged in as dd on https://registry.npmjs.org/.
  2. 查看npm登錄的信息:終端輸入npm config ls,在輸出的信息中有一個userconfig,複製後面的路徑,而後在終端打開這個文件就能夠查看登錄的信息。git

    ~ npm config ls
    
    ; cli configs
    metrics-registry = "https://registry.npmjs.org/"
    scope = ""
    user-agent = "npm/6.1.0 node/v6.11.1 darwin x64"
    
    ; userconfig /Users/dd/.npmrc
    loglevel = "http"
    progress = false
    registry = "https://registry.npmjs.org/"
    unsafe-perm = true
    
    // 查看用戶信息
    ~ cat /Users/dd/.npmrc
  3. 退出電腦上npm的用戶登錄:終端輸入npm logoutnpm

    ~ npm logout
    npm http request DELETE https://registry.npmjs.org/-/user/token/c4aba8ac-4699-42b8-bce1-3132b03e76f7
    npm http 200 https://registry.npmjs.org/-/user/token/c4aba8ac-4699-42b8-bce1-3132b03e76f7

3. 本地包發佈到npm

3.1 確認包的名字和版本

發佈的包的名字、版本就是項目目錄中package.json裏面的nameversionjson

3.2 發佈包到npm網站

終端打開項目,輸入npm publish:app

git:(master) ✗ npm publish
npm notice
npm notice 📦  gulu-201818-test@0.0.2
npm notice === Tarball Contents ===
npm notice 1.3kB package.json
npm notice 202B  .travis.yml
npm notice 1.4kB index.html
npm notice 153B  index.js
npm notice 1.7kB karma.conf.js
npm notice 1.1kB LICENSE
npm notice 131B  README.md
npm notice 2.3kB src/app.js
npm notice 230B  src/icon.vue
npm notice 2.2kB test/button.test.js
npm notice === Tarball Details ===
npm notice name:          gulu-201818-test
npm notice version:       0.0.2
npm notice package size:  5.3 kB
npm notice unpacked size: 13.5 kB
npm notice shasum:        a0fdb8f0ad6021100efffb3ff8b25efa14fcd97d
npm notice integrity:     sha512-aLvtUkXr3ACAB[...]NW7T2IYQ+4KNw==
npm notice total files:   12
npm notice
npm http request PUT https://registry.npmjs.org/gulu-201818-test
npm http 200 https://registry.npmjs.org/gulu-201818-test
+ gulu-201818-test@0.0.2

上傳成功後便可在npm網站查看你上傳的npm包:
圖片描述測試

4. 刪除上傳的包

注意:根據規範,只有在發包的24小時內才容許撤銷發佈的包( unpublish is only allowed with versions published in the last 24 hours)網站

因爲本人發佈的包是測試包,不但願污染npm網站,因此在測試成功後須要刪除包。this

終端打開包項目,輸入npm unpublish --force

git:(master) ✗ npm unpublish --force
npm WARN using --force I sure hope you know what you are doing.
npm http request GET https://registry.npmjs.org/gulu-201818-test?write=true
npm http 200 https://registry.npmjs.org/gulu-201818-test?write=true
npm http request DELETE https://registry.npmjs.org/gulu-201818-test/-rev/1-24b17efdba2140f2a1bb5033f1da6bcb
npm http 200 https://registry.npmjs.org/gulu-201818-test/-rev/1-24b17efdba2140f2a1bb5033f1da6bcb
- gulu-201818-test@0.0.2

此時再去npm網站上搜索這個包,發現已經不存在了:
圖片描述

相關文章
相關標籤/搜索