harpreetkhalsagtbit / country-state-city

Basic library for Country, State and City
country-state-city.vercel.app
GNU General Public License v3.0
282 stars 182 forks source link

bundle size too large #93

Open dennisteambrandit opened 2 years ago

dennisteambrandit commented 2 years ago

have issues with large bundle size (about 2mb gzip from just city/country/state data). when looking at bundle chunk, every city/country/state is being saved in the chunk even when i am only trying to import retrieve one country.

import {Country, State, City} from 'country-state-city'; const allCountries = Country.getCountryByCode('US')

harpreetkhalsagtbit commented 2 years ago

have you tried this

import {Country } from 'country-state-city';

instead of

import {Country, State, City} from 'country-state-city';

dennisteambrandit commented 2 years ago

i have tried and it seems to sort of reduce size when only retrieving one country. but bundle size is huge when retrieving more. even when usingimport {Country } from 'country-state-city'; Country.getAllCountries() returns huge bundle size over 2 mb which includes countries/states/cities

when i map through with 16 country.iso_codes with Country.getCountryByCode(c.country_code) i still get a bundle returned of over 2mb which includes countries/states/cities

harpreetkhalsagtbit commented 2 years ago

Next.js with Production Build

  1. with - import {Country, State, City} from 'country-state-city Screen Shot 2022-08-20 at 4 02 46 AM

  2. with - import { Country } from 'country-state-city Screen Shot 2022-08-20 at 4 04 55 AM

@dennisteambrandit

0wain commented 2 years ago

I also have this issue.

What I import. import { Country } from 'country-state-city'; How I use it. {{ props.user?.country_code ? Country.getCountryByCode(props.user.country_code).flag : '' }}

This is how big my build is including this.

This is how big my build is when I remove the above 2 lines

I'm using Laravel Mix, which uses webpack internally. All rather bizarre and odd.

vikas0sharma commented 1 year ago

Facing the same issue, bundle size is almost 16 MB. Any solution?

Vakil-Parth commented 1 year ago

+1

dhwrwm commented 1 year ago

This is stupidly big. I am afraid using this package will hugely impact on my performance.

harpreetkhalsagtbit commented 1 year ago

Reduced bundle size a little bit. Please check the latest version.