原创

laravel扩展包开发:将远程包改为本地包便于调试

前言

扩展包开发将远程 VCS 包改为本地加载,这里以我以前的 laravel 博客为范例,博客的目录如图:
file

一、将 laravel-admin 扩展包拉取到本地

1、创建本地包存放路径

在项目根目录下创建 packages 文件夹,用来存放我们的composer 扩展包

2、拉取composer扩展包

packages 文件夹下新建 encore 文件夹用来存放开发的扩展包,然后进入到 encore 文件夹,使用 git 拉取代码仓库中的 laravel-admin 项目代码。步骤如下:

git clone https://github.com/liangguifeng/laravel-admin.git

进入项目目录

cd laravel-admin

如图:
file

切换分支到 develop 开发分支上

git checkout -b develop  origin/develop

二、修改 composer.json 文件

1、示例代码

注意:此处需要修改示例代码中的:"encore/laravel-admin": "@dev",还有 repositories 下的包类型:"type": "path" 和包路径 "url": "packages/mallto/easy-mall" ,让其关联到我们刚刚拉取的扩展包
参考 composer.json 如图:

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.2",
        "ext-json": "*",
        "encore/laravel-admin": "*@dev",
        "fideloper/proxy": "^4.0",
        "friendsofphp/php-cs-fixer": "^2.15",
        "laravel/framework": "^6.2",
        "laravel/tinker": "^1.0",
        "medz/id-card-of-china": "^1.1",
        "overtrue/chinese-calendar": "^1.0",
        "overtrue/laravel-filesystem-qiniu": "^1.0",
        "overtrue/laravel-socialite": "~2.0",
        "sharemant/laravel-admin-ext-editormd": "*@dev"
    },
    "require-dev": {
        "facade/ignition": "^1.4",
        "fzaninotto/faker": "^1.4",
        "laravel/ui": "^1.1",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^3.0",
        "phpunit/phpunit": "^8.0"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "files":[
            "app/Helpers/helpers.php"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "repositories": [
        {
            "type": "path",
            "url": "packages/encore/laravel-admin"
        },
        {
            "type": "path",
            "url": "packages/sharemant/laravel-admin-ext-editormd"
        }
    ]
}

三、删除 composer.lock 文件

注意:很多人直接 composer install 了,发现项目并没有依赖到本地的扩展包,就是因为没有删除 composer.lock 文件,至于这个 composer.lock 文件有什么用,请去仔细阅读官方文档。

四、安装依赖,让其生成新的 composer.lock 文件

composer install

安装完毕后,就可以去使用本地的扩展包了

正文到此结束
本文目录