size-limit icon indicating copy to clipboard operation
size-limit copied to clipboard

Option to filter reported sections or allow passing custom options via command line

Open ctumolosus opened this issue 5 years ago • 5 comments

I have a monorepo with dozens of libraries. The value exported by the .size-limit.js module is built dynamically as an array of sections (i.e. {name: string, path: string}[]). Running the script with the --why option opens dozens of tabs on my browser. Ideally, I can pick one or more sections for introspection.

I tried passing custom options to modify the generated configuration, but size-limit bails when unknown options are passed via the command line. Ignoring unknown options is also a good enough solution for me as that would allow me to use a custom option to filter the results.

ctumolosus avatar Sep 15 '20 22:09 ctumolosus

Do you have an idea how to fix it?

ai avatar Sep 15 '20 22:09 ai

Take a look at #201 and let me know what you think.

ctumolosus avatar Sep 16 '20 12:09 ctumolosus

Will it be a better idea to pass environment variable? Like:

SHOW_WHY_FOR=3 npx size-limit

Environment variable is more easy to use in your code (process.env.SHOW_WHY_FOR), they do not require us to remove unknown argument error.

ai avatar Sep 16 '20 19:09 ai

Yeah, using environment variables is an option. My current workaround is to refer to the package directly after reviewing the bundle sizes.

npx size-limit --why ./path/to/package

I understand if you feel this is not the right direction for this library given I can already introspect the packages individually.

ctumolosus avatar Sep 16 '20 22:09 ctumolosus

We can add --why NAME support to the @size-limit/webpack and size-limit. NAME is a name: value from Size Limit config.

Do you like this API? You can send PR.

ai avatar Sep 16 '20 22:09 ai