npm发布自己的包

1、编写自己的组件

必须有入口js文件,暴露一个或者默认暴露,我的入口文件是message.js

逐个暴露

export const hanshu =()=>{}

 默认暴露

export default hanshu=()=>{}

2、建立新的文件夹

执行以下代码,初始化npm,初始化时写名字就好,其他默认

npm init

初始化完成后有package.json文件

{
  "name": "message-easy",
  "version": "1.1.0",
  "description": "message",
  "main": "message/message.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

 3、进入npm源

要进入npm官方的地址,不然会登录失败 

npm config set registry https://registry.npmjs.com/

 查看当前npm源

npm config get registry

切换回淘宝镜像

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

4、登录npm

npm login

依次输入用户名,密码,邮箱之后,会向你的邮箱发送验证码,最后输入验证码就好

5、发布 

npm publish

 发布成功后在npm官网进行搜索包名

6、使用

npm i 你所发布的包名

猜你喜欢

转载自blog.csdn.net/m0_57108418/article/details/130016788