发布自己的第一个npm/yarn包


参考官网:https://yarn.bootcss.com/docs/publishing-a-package/

一、Creating your first package

In order to create your first package, open up your system terminal/console and run the following commands:
新建一个文件夹,打开控制台,初始化包:

git init my-new-project
cd my-new-project
yarn init

注意命名规则:xxx-xxx-xxx
This is going to create a new git repository, put you inside of it, and then open up an interactive form for creating a new yarn project with the following questions:
输入一些相关信息:

name (my-new-project):
version (1.0.0):
description:
entry point (index.js):
git repository:
author:
license (MIT):

最后生成package.json:
Now you should have a package.json that looks similar to this:

{
  "name": "my-new-project",
  "version": "1.0.0",
  "description": "My New Project description.",
  "main": "index.js",
  "repository": {
    "url": "https://example.com/your-username/my-new-project",
    "type": "git"
  },
  "author": "Your Name <you@example.com>",
  "license": "MIT"
}

二、Logging into npm

If you haven’t already, you’ll first need to create an npm account. Once you’ve done that you can setup your username and email in Yarn.

首先需要注册一个NPM账号:https://www.npmjs.com/signup

注册登录之后:

yarn login

This will prompt you for your username and email. However, it will not ask you for your password. Yarn does not hold onto your password or any sessions. When you go to publish or modify something on npm, you will need to enter your password then.

如果你的npm镜像修改过,非官网,请求该成官网,例如淘宝镜像是不可以发布的。

报错:
question npm password: error Incorrect username or password.

解决方案:

# 1.将配置的registry重新指向npm官方
npm config set registry https://registry.npmjs.org/
# 2.登录发布
# 3.切回淘宝镜像
npm config set registry https://registry.npm.taobao.org 

三、Publishing your package

Once you have written all the code in your package, tested it out and you are ready to publish you can kick things off:

yarn publish

在这里插入图片描述
大功告成!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值