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网站上搜索这个包,发现已经不存在了:
图片描述

相关文章
相关标签/搜索