country-state-city icon indicating copy to clipboard operation
country-state-city copied to clipboard

bundle size too large

Open dennisteambrandit opened this issue 2 years ago • 8 comments

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')

dennisteambrandit avatar Jun 03 '22 19:06 dennisteambrandit

have you tried this

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

instead of

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

harpreetkhalsagtbit avatar Jun 06 '22 08:06 harpreetkhalsagtbit

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 using import {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

dennisteambrandit avatar Jun 06 '22 17:06 dennisteambrandit

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

harpreetkhalsagtbit avatar Aug 19 '22 22:08 harpreetkhalsagtbit

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.

0wain avatar Aug 22 '22 19:08 0wain

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

vikas0sharma avatar Dec 03 '22 14:12 vikas0sharma

+1

Vakil-Parth avatar Dec 21 '22 06:12 Vakil-Parth

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

dhwrwm avatar Mar 31 '23 17:03 dhwrwm

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

harpreetkhalsagtbit avatar Aug 19 '23 18:08 harpreetkhalsagtbit