I've used proguard to shrink android app packages before. It removes unused classes and files from app dependencies, even 3rd party ones, resulting in considerably lower package size. Is there an equivalent in node/npm ?
npm prune --production
removes dev dependencies, and node-prune partially removes unused files. But neither completely remove unnecessary code from within a 3rd party package.
You already mention the --production
flag and node-prune
in your question, so I'll leave those out. (You can also look at dmn
which is similar to node-prune
.)
If you are using a bundler like rollup
or webpack
, they can do tree shaking to remove code you're not using. (I'm not sure how much configuration is required to get it to safely work with a third-party module in node_modules
or even if that's possible.) In this case, tree shaking wouldn't remove the code from node_modules
though. Instead, these tools bundle everything into a single executable file and remove the unused code from there.