Composer : how to add a dependency without network connection?

前端 未结 2 1069
广开言路
广开言路 2021-01-03 00:07

My profesionnal network block internet access. Some month ago I download the Silex framework from an archive (which contains composer.json file) and the composer.phar one\'s

相关标签:
2条回答
  • 2021-01-03 00:38

    If you do not want to create a custom repository, you can also run composer install (or composer update) on a copy that is on a network-connected computer. Then you can copy over the newly added and extracted component into the vendor folder on the machine without internet access. Note that you also need to copy vendor/composer/installed.json to let composer know that the new package has been installed. Once you have copied all these files, you can run composer install on the machine without internet access and it will not try to install anything and dump autoload files.

    0 讨论(0)
  • 2021-01-03 00:43

    Thanks to edmondscommerce's comment I found the solution:

    I update my main composer.json file with an artifact respository (and I disable the packagist one):

    {
        "name": "user/silex",
        "repositories": [
            {
                "type": "artifact",
                "url": "artifact/"
            }, {
                "packagist": false
            }
        ], "require": {
            "silex/silex": "1.2"
                    , "twig/twig": ">=1.8,<2.0-dev"
                    , "monolog/monolog": "1.*"
                    , "doctrine/dbal": "2.2.*"
                    , "symfony/security": "~2.3"
        },
        "autoload": {
            "psr-4": {
                "Portal\\": "src/"
            }
        }
    }
    

    Then I put a folder called artifact according to the url put in the composer.json file.

    I create into this folder a zip called monolog-monolog-1.8.zip with the library I want to add.

    Then just launch a composer update command!

    Be carefull, zip's root must contain a composer.json file, and this composer.json file must contain a version!

    0 讨论(0)
提交回复
热议问题