打開網站:https://www.npmjs.com/,點擊頁面右上角sign up
打開註冊頁面:
注意: Full Name、Password和Public Email 註冊之後能夠修改,Username註冊後不可修改。
註冊後須要去郵箱中確認一下。html
npm 網站使用Gravatar頭像庫。
註冊好後,若是想修改默認頭像:vue
Change Your Gravatar
進入 Gravatar網站,若是沒有帳號請註冊一個帳號。My Gravatars
。Add email address
,輸入註冊npm帳號的郵箱,而後點擊Add
.Add a new image
,若是圖片在電腦上那麼選擇Upload new
,選擇一張圖片,點擊Next
,修剪一下圖片,點擊Crop Image
,選擇一個圖片級別,G全部人都能看,而後點擊Set Rating
, 而後點擊Do not use this image yet
.Confirm
,稍等一會便可完成。打開終端輸入命令:npm adduser
,依次輸入Username
、Password
、Email
,用戶名、密碼、郵箱都是在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/.
查看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
退出電腦上npm的用戶登錄:終端輸入npm logout
npm
~ 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
發佈的包的名字、版本就是項目目錄中package.json
裏面的name
和version
,json
終端打開項目,輸入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包:測試
注意:根據規範,只有在發包的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網站上搜索這個包,發現已經不存在了: