1.注册composer、github账号
2.在github上新增项目,并将项目克隆到本地环境
Administrator@DESKTOP-UI8EDNS MINGW64 /d/laravel_www
$ git clone [email protected]:Yinjinshui/pack-test-two.git
Cloning into 'pack-test-two'...
remote: Enumerating objects: 33, done.
remote: Counting objects: 100% (33/33), done.
remote: Compressing objects: 100% (21/21), done.
remote: Total 33 (delta 7), reused 22 (delta 5), pack-reused 0
Receiving objects: 100% (33/33), 6.49 KiB | 1.62 MiB/s, done.
Resolving deltas: 100% (7/7), done.
Administrator@DESKTOP-UI8EDNS MINGW64 /d/laravel_www
$ cd pack-test-two/
Administrator@DESKTOP-UI8EDNS MINGW64 /d/laravel_www/pack-test-two (master)
$ ls
README.md
3.composer构建项目
4.修改composer.json文件
{
"name": "two/test",
"description": "pack test two",
"type": "library",
"require": {
"php": "^7.2"
},
"license": "MIT",
"authors": [
{
"name": "json",
"email": "[email protected]"
}
],
"minimum-stability": "dev",
"autoload": {
"psr-4": {
"Two\\": "src/"
}
}
}
5.修改完composer.json,需要执行composer dump-autoload
D:\laravel_www\pack-test-two>composer dump-autoload
Generating autoload files
Generated autoload files
Administrator@DESKTOP-UI8EDNS MINGW64 /d/laravel_www/pack-test-two (master)
$ ls
composer.json composer.lock README.md vendor/
6 创建src目录(创建服务文件)
创建Tservice.php
7.创建test.php测试文件
getDate();
echo $time;
修改git忽略文件.gitignore(把改文件提交到远程仓库)【vendor文件可以不提交到远程仓库,获取代码没有vendor可以执行composer dump-autoload】
#/vendor/
8.提交文件到github远程仓库
Administrator@DESKTOP-UI8EDNS MINGW64 /d/laravel_www/pack-test-two (master)
$ git add .
warning: LF will be replaced by CRLF in .gitignore.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in composer.json.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in composer.lock.
The file will have its original line endings in your working directory.
g
Administrator@DESKTOP-UI8EDNS MINGW64 /d/laravel_www/pack-test-two (master)
$ git commit -m "备注"
[master 049278a] 备注
5 files changed, 189 insertions(+), 13 deletions(-)
create mode 100644 .gitignore
create mode 100644 composer.json
create mode 100644 composer.lock
create mode 100644 test.php
Administrator@DESKTOP-UI8EDNS MINGW64 /d/laravel_www/pack-test-two (master)
$ git push origin master
Enumerating objects: 11, done.
Counting objects: 100% (11/11), done.
Delta compression using up to 8 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (8/8), 2.10 KiB | 1.05 MiB/s, done.
Total 8 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:Yinjinshui/pack-test-two.git
18f75e7..049278a master -> master
Administrator@DESKTOP-UI8EDNS MINGW64 /d/laravel_www/pack-test-two (master)
9.在composer packagist提交项目,打开https://packagist.org/,点击右上角Submit,输入git地址,然后确认提交(把项目传递到packages)
git仓库地址粘贴到packages然后点击Check
点击提交操作
项目提交成功
10.组件包打标签(不熟悉git命令点击查看)
10.1命令方式打tag(方法一)
github远程仓库,推送成功的标签
10.2直接在github打标签(方法二)
在github项目中, 进入 release -> Draft a new release->Publish release
标签创建成功
11 github标签打包成功后,packagist点击更新
12.laravel 项目。执行 composer require two/test
Route::any('ziditwo',function(){
$obj=new \Two\Tservice();
return $obj->getDate();
});