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