1. 注册一个NPM账号
npm官方地址:https://www.npmjs.com/
2. 在本地创建一个目录,输入npm初始化命令,并修改package.json,创建src/index.js入口文件
npm init --yes
package.json
- name npm发布时的包名,和已有的npm库不能重复
- version 包版本号,更新时要修改为更高版本
- description 包的描述
- main 入口文件路径
3.根目录下添加LICENSE文件
- Copyright © 2020 Neo Han 日期、作者可自行修改
MIT License
Copyright (c) 2020 Neo Han
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4.发布npm
-
登录npm账号
npm login
-
查看npm账号
npm whoami
-
查看当前源是否官方地址
npm config get registry
-
如果不是官方源地址,要切换源地址
npm config set registry=https://registry.npmjs.org/
-
发布
npm publish