DEV Community

On NPM Packages and Bundle Size Impact

Ronni Egeriis Persson on June 12, 2019

Edit, June 13, 2019: What a timing... pika.dev have just been released, which is a CDN for ES modules. Their search engine also reveals which packa...
Collapse
 
thekashey profile image
Anton Korzunov

Tree shaking is not enough:

Collapse
 
egeriis profile image
Ronni Egeriis Persson

It is definitely not perfect. I would argue that the only way to move things forward, is if our dependencies ensure that we can tree shake, then we can start optimizing the mechanics. This is, however, not possible at all with CommonJS modules.

I'll check our your post later, looks super interesting, thanks for sharing!

Collapse
 
thekashey profile image
Anton Korzunov

Both rollup and parcel could tree shake CommonJS (terms and conditions apply).
For a better context just into this loooooong conversation - twitter.com/rich_harris/status/113...

Thread Thread
 
egeriis profile image
Ronni Egeriis Persson

My understanding is that webpack can do this too, but it's experimental as there are often side effects that webpack will not be able to see through code analysis. webpack.js.org/guides/tree-shaking...

Collapse
 
dotnetcoreblog profile image
Jamie

I've seen a lot of folks include a full npm and webpack stack for things which really could have been handled better with vanilla JS. I'm not advocating for one over the other, but I feel like more folks could look at whether they need to use systems like npm in order to build their apps.

Putting that to one side, I really like what you've said here. I've used npm packages in the past which even had debugger and console.log statements in them, so I feel like (as with all languages and frameworks) it's worth library authors taking the time to figure out how to produce a smaller, tighter, faster version of their bundles.

Collapse
 
egeriis profile image
Ronni Egeriis Persson

100% agree. And with more and more focus on possible insecurities of NPM packages, there are added emphasis on picking packages only when they're truly valuable.