Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Check against total file size #205

Closed
manniL opened this issue Mar 15, 2018 · 4 comments
Closed

Feature: Check against total file size #205

manniL opened this issue Mar 15, 2018 · 4 comments

Comments

@manniL
Copy link

manniL commented Mar 15, 2018

Do you want to request a feature or report a bug?

A feature

What is the current behavior?

Bundlesize currently checks if each file is below the threshold.

What is the expected behavior?

With a flag set (e.g. checkAgainstTotal), bundlesize should sum up the size of all (selected) files and check it against a threshold.

If this is a feature request, what is motivation or use case for changing the behavior?

In times of code splitting, it can happen that you have 100 files <3kb, but in the end, this still means that the app is large.

@siddharthkp
Copy link
Owner

siddharthkp commented Mar 16, 2018

Thanks for taking the time!

bundlesize tries to shy away from total size because the performance of a page depends a lot on the way the individual bundles load (prefetch/lazy-load/on-demand, etc.)

We've had discussions around total in the past and it doesn't make sense to drive confidence from a metric that is biased/nuanced.

One strategy that has worked for teams using bundlesize is to measure initial bundles and chunks with different thresholds:

"bundlesize": [
  { "path": "./dist/feature-*.js", "maxSize": "30 kB"},
  { "path": "./dist/chunk-*.js", "maxSize": "5 kB" }
]

Let me know if that's a satisfactory answer, I can talk about this in more detail if you'd like

@manniL
Copy link
Author

manniL commented Mar 16, 2018

@siddharthkp Thanks for that fast answer! I understand now why the measurement of individual files makes more sense than measure the total file size. ☺️

@vanslly
Copy link

vanslly commented Jan 3, 2020

Total size makes sense for setting a library size budget for an npm package you publish, but where you don't want to bundle the package and leave bundling to consumers. Sure the consuming application could cherry-pick & tree-shake the code paths unused, but as a library author it still makes sense to measure & set budgets for the code published in an npm package.

To achieve this I'm resorting to rollup to generate a bundle for me, and then I run bundlesize over this bundle. This bundle is simply for bundlesize, so I discard this bundle once done.

@siddharthkp
Copy link
Owner

siddharthkp commented Jan 3, 2020

@vanslly that's great implementation, thanks for leaving it here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants