hypeserver / react-date-range

A React component for choosing dates and date ranges.
MIT License
2.59k stars 672 forks source link

Importing one locale bundles everything #376

Closed maxaggedon closed 4 years ago

maxaggedon commented 4 years ago

[BUG] Bug Reproduce Steps

When importing locale like this import { fr } from "react-date-range/dist/locale", we import every locale re-exported from date-fns. In my case (fr locale), it added 77KB of unused files after gzip.

[BUG] Expected behaviour

Import only the necessary one.

Environment

Package Version: 1.0.3

keremciu commented 4 years ago

@maxaggedon oh okay but you can import directly from date-fns right? but I'm not sure it's supporting tree shaking

maxaggedon commented 4 years ago

@keremciu yes I did that, I just wanted to raise attention about this because documentation suggests to use re-exported locales, and maybe it should instead suggest to import only the used ones from date-fns like so :

import fr from "date-fns/locale/fr";
keremciu commented 4 years ago

@maxaggedon yep, definitely it should be like that. I think there's no reason to export locales again. I'm thinking about removing them and just leave enUS locale import for default then we can just say please use locale from date-fns like you write in your comment

ghost commented 4 years ago

See https://github.com/date-fns/date-fns/blob/master/docs/webpack.md. It can be imported dynamically