Skip to content

Instantly share code, notes, and snippets.

@carlovsk
Created January 31, 2022 02:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlovsk/8ba655431c720721212ad3b337ab8e36 to your computer and use it in GitHub Desktop.
Save carlovsk/8ba655431c720721212ad3b337ab8e36 to your computer and use it in GitHub Desktop.
List heavy deps from a given string - which is an output from the command `du -skh node_modules/*` on your project.
const listHeavyPackages = packages => packages.split(`\n`).forEach(packageRow => {
if (packageRow === ``) return
const [s, p] = packageRow.split(`\t`)
const size = s.trim()
const package = p.trim()
if (size.includes('M')) console.log(`${package} might be a heavy package: ${size}`)
})
@carlovsk
Copy link
Author

carlovsk commented Jan 31, 2022

This snippet will show you the dependencies of your project that are heavier than 1M. For that, you'll need the list of all of your deps and their sizes. You can do it by:

$ cd yourProject/
$ du -skh ./node_modules/* >> deps.txt

Go to the file deps.txt and all of your deps will be there. Copy the content, paste on any JavaScript console inside a variable and call the function. Just like that:

const packages = `500K	@algolia
564K	@aws-crypto
 48M	@aws-sdk
6.1M	@babel`

listHeavyPackages(packages)

The output will look like this:

./node_modules/@aws-sdk might be a heavy package: 48M
./node_modules/@babel might be a heavy package: 6.1M
./node_modules/@types might be a heavy package: 1.1M

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment