Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tell composer to install minimum files

I've got a composer.json to require twig:

"require": {
        "twig/twig": "~1.0",
        ...
}

This twig package installs a folder called doc.

Basically, my vendor folder is getting too large, especially since I distribute my project with it (it's a WordPress plugin).

Is there a way to tell composer to only include "minified" or at least least amount of files not not things like documentation, tests, etc?

like image 584
Gezim Avatar asked Feb 18 '17 19:02

Gezim


People also ask

How can I speed up my Composer install?

Yes, removing the lock file would make for a slow install. composer install uses the lock file to speed up installations.

What is difference between require and require Dev in Composer?

require: These are must packages for the code to run. It defines the actual dependency as well as package version. require_dev: It defines the packages necessary for developing the project and not needed in production environment. Note: The require and require_dev are important parameters available in composer.


1 Answers

You can not, because you(as a dependency client) are not eligible to make decision about how your dependency should act. Its up to him! Just deliver your projects without dependency files in it, instead include composer.json.

This question has been asked before, every time with answer No or sth similar to it.
Here are some examples:
How to install specific files from a package using composer.json
How to config composer.json to retrieve specified files only?


UPDATE ## [important!]

It seems there is only one way somehow similar to what you need.

There is an option which composer-friendly projects developers may or may-not use, and its a tricky play with --prefer-dist & .gitattributes files.
The developer could use .gitattributes file to ignore some of the files and folders during packaging for the --prefer-dist mode. sth like this:

/docs               export-ignore
/tests              export-ignore
/.gitattributes     export-ignore
/.gitignore         export-ignore
/phpunit.xml        export-ignore

Then while providing dependencies, Packagist uses these .zip file made in github to pull in the --prefer-dist dependencies, and then unarchives them once downloaded (much faster than cloning). Thus, If the developer, ignores tests, docs and other logically irrelevant files by listing them in .gitattributes, the archives won’t contain them, becoming much, much lighter.

It seems this is the only way, which again, is not based on code-client decision & obviously is a Producer-Developer-Oriented method.

But after all, you can check --prefer-dist while installing your desired dependency, may they've made this option available & you can get a much lighter version.

like image 78
BehradKhodayar Avatar answered Sep 20 '22 15:09

BehradKhodayar