1. 注册npm账号
打开网站:,点击页面右上角sign up
打开注册页面:
1.1 修改npm用户的默认头像
npm 网站使用Gravatar头像库。
注册好后,如果想修改默认头像:- 点击页面右上角头像-> Profile Settings,进入个人设置页面:
- 点击头像下面的
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网站用户头像同步需要稍等一会才能看见。
2. 电脑本地npm登陆
-
打开终端输入命令:
npm adduser
,依次输入Username
、Password
、Email
,用户名、密码、邮箱都是在npm上注册的。~ npm adduser npm http request → POST https://registry.npmjs.org/-/v1/loginnpm http 401 ← Unauthorized (https://registry.npmjs.org/-/v1/login)Username: ddPassword:Email: (this IS public) dd@163.comnpm http request → PUT https://registry.npmjs.org/-/user/org.couchdb.user:ddnpm 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
,复制后面的路径,然后在终端打开这个文件就可以查看登陆的信息。~ npm config ls; cli configsmetrics-registry = "https://registry.npmjs.org/"scope = ""user-agent = "npm/6.1.0 node/v6.11.1 darwin x64"; userconfig /Users/dd/.npmrcloglevel = "http"progress = falseregistry = "https://registry.npmjs.org/"unsafe-perm = true// 查看用户信息~ cat /Users/dd/.npmrc
-
退出电脑上npm的用户登陆:终端输入
npm logout
~ npm logoutnpm http request DELETE https://registry.npmjs.org/-/user/token/c4aba8ac-4699-42b8-bce1-3132b03e76f7npm http 200 https://registry.npmjs.org/-/user/token/c4aba8ac-4699-42b8-bce1-3132b03e76f7
3. 本地包发布到npm
3.1 确认包的名字和版本
发布的包的名字、版本就是项目目录中package.json
里面的name
和version
,
3.2 发布包到npm网站
终端打开项目,输入npm publish
:
git:(master) ✗ npm publishnpm noticenpm notice ? gulu-201818-test@0.0.2npm notice === Tarball Contents ===npm notice 1.3kB package.jsonnpm notice 202B .travis.ymlnpm notice 1.4kB index.htmlnpm notice 153B index.jsnpm notice 1.7kB karma.conf.jsnpm notice 1.1kB LICENSEnpm notice 131B README.mdnpm notice 2.3kB src/app.jsnpm notice 230B src/icon.vuenpm notice 2.2kB test/button.test.jsnpm notice === Tarball Details ===npm notice name: gulu-201818-testnpm notice version: 0.0.2npm notice package size: 5.3 kBnpm notice unpacked size: 13.5 kBnpm notice shasum: a0fdb8f0ad6021100efffb3ff8b25efa14fcd97dnpm notice integrity: sha512-aLvtUkXr3ACAB[...]NW7T2IYQ+4KNw==npm notice total files: 12npm noticenpm http request PUT https://registry.npmjs.org/gulu-201818-testnpm 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网站,所以在测试成功后需要删除包。
终端打开包项目,输入npm unpublish --force
:
git:(master) ✗ npm unpublish --forcenpm WARN using --force I sure hope you know what you are doing.npm http request GET https://registry.npmjs.org/gulu-201818-test?write=truenpm http 200 https://registry.npmjs.org/gulu-201818-test?write=truenpm http request DELETE https://registry.npmjs.org/gulu-201818-test/-rev/1-24b17efdba2140f2a1bb5033f1da6bcbnpm http 200 https://registry.npmjs.org/gulu-201818-test/-rev/1-24b17efdba2140f2a1bb5033f1da6bcb- gulu-201818-test@0.0.2
此时再去npm网站上搜索这个包,发现已经不存在了: