首先你得在官网注册一个npm帐号npm
好比咱们新建一个index.js文件 这个文件只打印一句话 ,而后把这个文件发布成一个npm包json
npm init
bash
执行这个操做会在本地生成一个package.json文件,而且按照提示输入相应的描述 版本号等等。spa
{
"name": "charllote-bao",
"version": "1.0.0",
"description": "test",
"main": "index.js",
"scripts": {
"test": "npm install charllote "
},
"author": "charllote",
"license": "ISC"
}
复制代码
npm login
code
npm publish
ip
若是遇到如下提示报错,说明你可能注册以后没有去验证邮箱,打开你绑定的邮箱,点击npm的验证连接便可。get
npm ERR! code E403
npm ERR! 403 Forbidden - PUT https://registry.npmjs.org/charllote-bao - you must verify your email before publishing a new package: https://www.npmjs.com/email-edit
复制代码
发布成功以后能够在你的npm主页看到刚发布的包string
npm version patch // 这个操做会在原先的版本号上+1
npm publish // 从新发布
复制代码
执行成功后会在主页看到一个新发布的版本包it
删除指定的包和版本号io
npm unpublish 包名@版本号
复制代码