7

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?

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
Gezim
  • 7,112
  • 10
  • 62
  • 98
  • https://getcomposer.org/doc/04-schema.md#exclude-files-from-classmaps – ʰᵈˑ Feb 24 '17 at 12:02
  • 1
    If you are distributing it as a package why don't you just write a task to remove the extra files before you publish – Pitchinnate Feb 24 '17 at 21:37
  • @Pitchinnate Because that's error prone. Upgrading packages will not be straight-forward. Also, I shouldn't be the one to decide what's not 100% necessary for distribution, it should be package maintainer. – Gezim Feb 24 '17 at 22:39

3 Answers3

6

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.

Community
  • 1
  • 1
behkod
  • 2,647
  • 2
  • 18
  • 33
0

I don't know if i understood your question correctly. But if you build a plugin you don't provide the vendor folder instead you write you dependencies in your composer.json file and the user that want to use your plugin download that sources in his vendor folder as dependency that is needed for your plugin.

I don't think that your can "minify" your dependencies.

René Höhle
  • 26,716
  • 22
  • 73
  • 82
  • Think of it this way: I'm distributing this code as it make not sense not to. The "plugin" here is a distributable package. – Gezim Feb 20 '17 at 06:14
  • 1
    I agree with @Stony about the fact that you're not supposed to distribute your vendor folder. One possible solution is to add a post-install script to download the vendor dependencies. I will still upvote your question, because anyway, it woul be nice to not download all those documentation. – jlHertel Feb 25 '17 at 18:57
0

Simple anwser is You can't.

Composer install package in a way that is defined in composer.json in package repository. And (package) author decide what should be in it. That's the idea here .

The idea of composer is that you distribute your code without vendor dir, and "client" should run composer install on his side.

And it's normal that vendor dir takes a lot of space :/

Michał G
  • 2,234
  • 19
  • 27