发布自己的第一个npm/yarn包
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了发布自己的第一个npm/yarn包相关的知识,希望对你有一定的参考价值。
目录
- 一、Creating your first package
- 二、Logging into npm
- 三、Publishing your package
参考官网: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
大功告成!
以上是关于发布自己的第一个npm/yarn包的主要内容,如果未能解决你的问题,请参考以下文章