Absolutely, this is a common question for teams deploying Laravel/VueJS applications. Here are direct answers to your questions:
- Is it a good idea to remove unused packages?
- Yes, but only if "unused" means the package is not required (not referenced in your codebase nor as a dependency of another package you use). Removing required packages can break your application. So, it needs to be done carefully and systematically, not manually deleting folders from
vendor/ornode_modules/.
- Is there a safe way or package to help with this?
For PHP/Laravel (Composer packages):
-
Use
composer unused:
This tool analyzes your codebase and tells you which Composer packages are installed but are not actually used by your project.Installation:
composer global require composer-unused/composer-unusedUsage:
composer unusedThis will list all unused composer packages. You can then remove them using:
composer remove <package-name>
For Node.js/VueJS (npm/yarn packages):
-
Use
depcheck:
This tool checks for unused npm dependencies.Installation:
npm install -g depcheckUsage (from your project directory):
depcheckThis will show a list of unused dependencies and devDependencies. You can then remove them with:
npm uninstall <package-name>or
yarn remove <package-name>
Best Practices:
- Always commit your current version (or make a backup) before removing packages, so you can recover if needed.
- Sometimes these tools can give false positives, especially for packages loaded dynamically or used in artisan commands/config files. Review the suggestions before removal.
Summary Code:
Composer (PHP/Laravel):
composer global require composer-unused/composer-unused
composer unused
composer remove <package-name>
NPM/Yarn (Node/Vue):
npm install -g depcheck
depcheck
npm uninstall <package-name>
Note: Never remove packages directly from vendor or node_modules — always use the relevant package manager to keep your dependency tree healthy.
If you need guidance interpreting the output of these tools, or want to automate post-removal testing, let me know!