node.js – What techniques can help me identifying unused dependencies for a production build?

The Dev Dependencies are only installed when doing a full npm install (usually locally). These usually include testing type of dependencies or other dependencies only needed for the local development environment.

By running run npm install --production during the production pipeline build will only install the dependencies and not the Dev Dependencies in package.json. These dependencies are the ones required for your deployed package to run correctly.

To see if you have dependencies that are not used, you can use something like www.npmjs.com/package/depcheck (depcheck) to remove dependencies that are not used. This will make your deployed packages smaller. Also, please note there are other tools out there as well to manage un-used dependencies.

Sometimes, Dev Dependencies end up in the Dependency tree used for production builds. In these cases, simply move the dependency to a Dev Dependency and it will no longer be included in the production build. NPM installs without the --production flag will still install it for local (non-production) use.

Read more here: Source link