目录
- 一、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:
新建一个文件夹,打开控制台,初始化包:
注意命名规则: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:
输入一些相关信息:
最后生成package.json:
Now you should have a package.json that looks similar to this:
二、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
注册登录之后:
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.
解决方案:
三、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:
大功告成!