解决问题:
npm login 403 报错 镜像一直是淘宝镜像,需要切换到npm镜像
npm config set registry https://registry.npmjs.org/
重新改回淘宝镜像
npm config set registry http://registry.npm.taobao.org/
npm 发包流程(前提要有npm账号)
npm login //npm 登录
创建项目:
mkdir lzy_jci-test-pkg
npm 官方建议发布的包至少包含:
1.package.json(包的基本信息)
2.README.md(文档)
3.index.js(入口文件)
npm init //初始化package.json
//package.json
//这里的name就是包名,不能跟npm库中的包同名
{
"name": "lzy_jci-test-pkg",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "lzy_jci",
"license": "ISC"
}
创建README.md文件
this is my first npm package!
just for learning.
创建index.js文件
module.exports = {
testMsg: function() {
console.log("this is my first npm package test!")
},
test:1
}
最后的目录结构
执行命令
//发包
npm publiss
发包完成
npm 查看