1.在npm官网注册账号
2.切换npm源
npm config set registry https://registry.npmjs.org/
3.打开cmd并cd到要发布的项目目录,登录
npm login
//需要输入用户名,密码,邮箱
4.配置基础信息
npm init
5.配置信息如下
{
"name": "test123456",//name是npm包的名称
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
6.新建index.js
module.exports = function() {
console.log('哈喽,这是一个npm包测试')
}
7.发布
npm publish
8.删除已发布的包
npm --force unpublish test123456