如何发布本身的composer包

前提:
你须要收github和Packagist帐号
github地址:https://github.com
Packagist地址:https://packagist.orggit

一:将你的composer包代码上传到github上
如何上传代码到github上能够参考个人:github 简单使用
若是你须要能够实现composer下载,那么你的composer包中必需要有composer.json文件
composer.json文件基本格式你能够按照以下格式编写:github

{
    "name": "huaweichenai/baidu-discern",
    "description": "Baidu realizes picture recognition text package(百度实现图片识别文字包)",
    "keywords": ["yii2","baidu","discern","extension"],
    "type": "yii2-extension",
    "license": "BSD-3-Clause",
    "authors": [
        {
            "name": "huaweichenai",
            "email": "243681093@qq.com",
            "homepage": "https://www.wj0511.com/"
        }
    ],
    "require": {},
    "minimum-stability": "dev",
    "autoload": {
        "psr-4": {
            "huaweichenai\\discern\\": "src"
        }
    }
}

二:将composer包上传到packagistjson

1:登陆packagist而后点击右上角的submit按钮yii2

2:在输入框中输入你的github代码仓库地址,而后点击checkcomposer

clipboard.png

若是出现错误根据错误提示解决,没有错误点击submityii

等到submit执行事后出现以下界面表示你的composer包已经上传packagist上了ui

clipboard.png

虽然咱们已经将comspoer包上传到packagist上了,可是咱们在本地安装咱们的composer包时仍是会报错的spa

clipboard.png

这是由于咱们没有在github上指定版本的缘由,若是咱们不想在github上指定版本,这时候咱们能够执行3d

composer require huaweichenai/baidu-discern "dev-master"  #huaweichenai/baidu-discern是个人composer包

这时候就能够将咱们的composer包下载下来了code

咱们也能够在github上指定版本,那么如何在github上指定版本呢?

1:点击releases

clipboard.png

2:点击Create a new release
clipboard.png

3:发布一个版本
clipboard.png

4:发布一个版本以后咱们在packgist上点击update进行更新,这时候咱们就能够在本地不进行指定版本安装了

composer require huaweichenai/baidu-discern

将发布包上传到 Packagist 后可能须要几分钟才能够使用,若是出现问题,等过几分钟在进行安装就能够了

相关文章
相关标签/搜索