vincent15000's avatar

Remove unused packages to get the smaller application size

Hello,

Hmmm ... a client asks me if it's possible to reduce the size of a Laravel / VueJS application by removing all unused packages, so that it gets the smaller size possible.

The PHP and NodeJS packages in the vendor and node_modules folder are not all used, but sure they are dependencies. I think it's a very bad idea to try to remove some packages manually.

2 questions :

  • is it a good idea to remove the unused packages ?

  • if yes, is there any package to do that ?

Thanks for your help.

V

0 likes
6 replies
LaryAI's avatar
Level 58

Absolutely, this is a common question for teams deploying Laravel/VueJS applications. Here are direct answers to your questions:

  1. 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/ or node_modules/.
  1. 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-unused
    

    Usage:

    composer unused
    

    This 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 depcheck
    

    Usage (from your project directory):

    depcheck
    

    This 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!

vincent15000's avatar

composer-unused seems to be interesting, but it seems that it scans only the composer packages and not all the packages in the vendor folder.

jlrdw's avatar
jlrdw
Best Answer
Level 75

Just don't remove the standard packages that come in the vendor folder. However development only packages I always remove for production, but I'm sure you knew this already.

These I delete from composer when installing on production:

    "require-dev": {
        "fakerphp/faker": "^1.23",
        "laravel/pail": "^1.2.2",
        "laravel/pint": "^1.24",
        "laravel/sail": "^1.41",
        "mockery/mockery": "^1.6",
        "nunomaduro/collision": "^8.6",
        "phpunit/phpunit": "^11.5.50"
    },

On these, do you use all of them?

{
    "$schema": "https://www.schemastore.org/package.json",
    "private": true,
    "type": "module",
    "scripts": {
        "build": "vite build",
        "dev": "vite"
    },
    "devDependencies": {
        "@tailwindcss/vite": "^4.0.0",
        "axios": "^1.11.0",
        "concurrently": "^9.0.1",
        "laravel-vite-plugin": "^2.0.0",
        "tailwindcss": "^4.0.0",
        "vite": "^7.0.7"
    }
}
1 like
Snapey's avatar

what problem is the client trying to fix?

1 like
vincent15000's avatar

I think that he just wants to have the smallest Docker package possible.

I don't know if there is another goal.

Please or to participate in this conversation.