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.
You can't remove it completely, node_modules
is needed to run your script. And you may think there are unused files but they're still needed in some cases.
So let's check it carefully when doing such things. If the total file size is your matter. I recommend to use this tool: https://github.com/tj/node-prune
It gives you some options to control which to remove or not.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.