What is the best way to prepare a project for deploy?
Hi everyone. I'm starting my first Laravel project and I want to optimize it, specifically removing unnecessary modules that were useful during development but are unlikely to be used anymore. Could you tell me which packages I can definitely remove?
There is generally no need. In production, composer will install the packages required for production, and not those required for dev.
If you are thinking that your project is a lot of files to copy to your server, then rethink your approach. Production should involve cloning your code repository and running composer install.
If by "modules" you mean packages, the development packages (for example, PHPUnit or FakerPHP) are already marked as dev dependencies. During deployment, you won't install them:
composer install --no-dev
Now, is this an optimization? Not really. Optimization isn't about deleting files, it's about caching configs, routes, improving queries, etc..
You don't need to do anything except use the proper environment values.
If you only use certain packages only during development, you should install them as dev dependencies with composer / npm, and then they won't get installed in production. If you use Vite to build front-end assets, it only includes code and assets you've used.
If the project has some original scaffolding files you know aren't used, you can of course safely remove them. But don't go about deleting files unless you know what they do, and test every change in development.
In your composer.json file, you have a collection of packages under "require" and "require-dev". If the packages were only used during dev, and not for production, then you should be putting them in require-dev. In your deploy, you would add the --no-dev flag to the composer install command.
composer install --no-dev --optimize-autoloader
This would avoid installing all the testing packages, etc.