Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composer: Huge vendor folder

I am experimenting with Composer and coming from a RubyGems/Bundler background, it does exhibit some interesting behavior.

I tried creating a new Laravel project and to my surprise, I discover that I end up with a vendor folder that is beyond 70 megabytes in size.

While Laravel does offer a lot of functionality, I found the size to be bizarre, so I examined the contents of the vendor folder and discovered that it contains not just code, but also unit tests, documentation and entire git histories. For Swiftmailer, I even found lenghty RFC's for various e-mail standards.

While it's convenient to access specs and repository history for the dependencies, it does create a rather time-consuming deployment process and it litters the production server with irrelevant data.

I do understand that I could probably write an artisan command to "build" the app and dust off the dependencies by nuking all git histories, but it does seems like a dirty solution to a problem that has probably already been solved.

So the question is: Is there an approach to install composer dependencies, so only the code actually neccessary for running the (Laravel) app is downloaded?

Update: Using --prefer-dist

I have discovered that you can pass the --prefer-dist option when creating a new project, .e.g

composer create-project laravel/laravel my-new-project --prefer-dist

This makes Composer prefer zipped distributions over obtaining the source directly from the VCS (e.g. GitHub)

This rids you of the git histories and reduces the vendor folder to 17 megabytes. However, specs, documentation, e.g. is still included. So it would be nice if there was a way to push it down to a couple of megabytes.

like image 307
Niels B. Avatar asked Jan 06 '14 20:01

Niels B.


People also ask

Should I Gitignore vendor folder?

The general recommendation is no. The vendor directory (or wherever your dependencies are installed) should be added to . gitignore / svn:ignore /etc. The best practice is to then have all the developers use Composer to install the dependencies.

What is vendor folder in PHP?

The vendor is a subfolder in the Laravel root directory. It includes the Composer dependencies in the file autoload. php. Composer is a PHP based tool for dependency management. As a Laravel project works with many libraries, it requires the Composer for dependency management.

What is vendor folder?

The vendor folder is where you usually (I'm using the word 'usually' because it's not exactly a rule but more of a preference in the coding community with the purpose of having a semantic directory structure) keep third-party resources(icons, images, codes, you name it) as opposed to a lib (library) folder where you or ...


2 Answers

You might want to take a look at this package:

https://github.com/barryvdh/composer-cleanup-plugin

You could even improve upon this, I don't know if it removes the .git repositories as well etc..

like image 134
SamV Avatar answered Oct 17 '22 14:10

SamV


My vendor folder has a size of about 17 MB. Not sure what went wrong with your installation, but 70 MB is not the size it should have. I'm using Laravel 4.1. As far as I remebmer I downloaded it from Github as .zip (https://github.com/laravel/laravel/archive/master.zip) and then let Composer do the "install".

like image 1
chris342423 Avatar answered Oct 17 '22 15:10

chris342423