如何上传自己的组件到npm

80 阅读1分钟

1.注册npm账号

ps:如果使用淘宝镜像,需要切换回原镜像

// 查询镜像源
npm config get registry
// 出现这个https://registry.npmjs.org/则是官方源不必修改
// 登录
npm login // 弹出npm登录注册地址
npm init // 初始化package.json 配置包

2.package.json 配置

{
  "name": "small_monitor", //  名字
  "version": "1.0.0", // 版本号
  "description": "前端性能监察工具", // 介绍
  "main": "index.js", // 入口
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "xiaocai", //作者
  "license": "ISC", 
  "dependencies":{ //需要的依赖
    "error-stack-parser": "^2.1.4",
    "rrweb": "^2.0.0-alpha.4",
    "ua-parser-js": "^1.0.37"
  }
}

3.上传

同级目录创建index.js作为启动入口

npm publish // 上传插件

4.使用

npm i small_monitor

按文档引入即可

5.最后

记得换回淘宝镜像

npm config set registry https://registry.npm.taobao.org/