npm包发布流程
2020-04-15 本文已影响0人
一懒众衫小小小小
npm包发布流程
1. 注册npm账号
方式一: 通过npm官网注册
方式二: 通过终端注册
$ npm adduser
Username: YOUR_USER_NAME
Password: YOUR_PASSWORD
Email: YOUR_EMAIL@domain.com
查看npm当前使用的用户
$ npm whoami
2. 在终端登录npm账号
$ npm login
个人账号:
$ username: wenzhen
$ password: wen&1005
$ email: linkjane@163.com
3. 创建npm包
npm init packagename -y
or
npm init (已创建文件情况下)
在生成的package.json中修改配置信息
必须带有的字段
name :包名(全部小写,没有空格,可以使用下划线或者横线)
version: 版本
其他内容
author:作者信息
main:程序入口文件,一般都是 index.js
description:描述信息,有助于搜索
keywords:[] 关键字,有助于在人们使用 npm search 搜索时发现你的项目
scripts:支持的脚本,默认是一个空的 test
license:默认是 MIT
bugs:当前项目的一些错误信息,如果有的话
dependencies:在生产环境中需要用到的依赖
devDependencies:在开发、测试环境中用到的依赖
repository:代码仓库
4. 发布程序包到npm
将npm源切换为https://registry.npmjs.org/
nrm ls
nrm current
nrm use npm
或直接设置
npm set registry https://registry.npmjs.org/
cd到项目所在目录.执行一下命令发布项目
npm publish
package.json示例
{
"name": "regexp-rules",
"version": "1.0.0",
"description": "常用正则表达式校验规则",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/FernAbby/regexp-rules.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/FernAbby/regexp-rules/issues"
},
"homepage": "https://github.com/FernAbby/regexp-rules#readme"
}
npm升级包的版本
npm version <update_type>
patch:是补丁的意思,补丁最合适;
minor:小修小改;
major:大的版本变更;
npm version patch
npm version minor
npm version major
查看包信息
// 查看包版本信息
npm view antd versions
// 查看本地版本
npm ls antd
npm info antd
npm list
// 更新包
npm update antd