Skip to content

Instantly share code, notes, and snippets.

@nombrekeff
Last active February 8, 2020 22:14
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 nombrekeff/e83ebcba4058da5dfd0103158afcc7b3 to your computer and use it in GitHub Desktop.
Save nombrekeff/e83ebcba4058da5dfd0103158afcc7b3 to your computer and use it in GitHub Desktop.
This is a test ghowda blog (javascript, demo)
{
"labels": ["test", "javascript"],
"title": "Blog 1"
}

npm recently added Unpacked Size to the package details, I then realized one of my libraries was way too big (350kb) for the code it has...

I started looking into it, and realized a lot of files were being packaged and uploaded, even though they are ignored in .gitignore.

The solution to this was to use .npmignore and ignore all the files you want to ignore, I knew about .npmignore but never thought of trying it out.

As mentioned in the comments, this could also be accomplished using the files property in package.json.

I also used a tool called size-limit that calculates the real cost to run your JS app or lib, thanks to this I changed a couple of dependencies that were way too big for the use case, and reduced the size even more.

Some libraries I changed:

Before Size After Size
cli-color 98.7 kb colors 39.5 kb
requests 201 kb phin 10.1 kb

As you can see, this makes a huge difference (-250 kb) for a little library.

I reduced the package from 359kb to 59kb, around -83% size difference :P

Notice

If you are starting out, please don't waste time optimizing your code until you understand why and how you are optimizing, premature optimization is evil and can cause bigger issues.

@nombrekeff
Copy link
Author

Okay... gonna start testing out the comments

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