ekwonye-richard / react-flags-select

Customizable svg flags select components for React Js
194 stars 121 forks source link

Is there a way to avoid including all the flags in the bundled output? #109

Closed davecranwell closed 2 years ago

davecranwell commented 3 years ago

I've been evaluating this for use in a project with a really aggressive performance budget, and this library seems to be adding hundreds of KB of flags I'm not using. In fact I really only want a max of 10 flags.

Is there a way I could exclude all the ones I'm not using at build-time, that I'm missing?

FlorianCassayre commented 2 years ago

Hi, I'm running into the same issue. On my side, even when importing the flags individually the whole package is bundled:

import { Gb } from 'react-flags-select';

This is quite annoying and as such is preventing me from including this library in my project.

Perhaps the owners of this repository could try to set the following field in package.json:

{
  ...
  "sideEffects": false
}
FlorianCassayre commented 2 years ago

:tada: Good news, I managed to tweak the config to enable proper tree shaking. I'll submit a PR when I have time, but essentially here are the changes that I made:

Here is the result after making these changes and importing a single flag in my same project (import { De } from 'react-flags-select'):

image

As a comparison, the bundle used to be 850kB before making these changes (essentially containing all the flags).