Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing unneeded timezones from bundle #292

Open
bteng22 opened this issue Dec 14, 2017 · 2 comments
Open

Removing unneeded timezones from bundle #292

bteng22 opened this issue Dec 14, 2017 · 2 comments

Comments

@bteng22
Copy link

bteng22 commented Dec 14, 2017

Sorry if this is a trivial question/if this isn't the correct avenue, but is there any way to remove timezones and locales that are unused? My team and I only need to determine the time in the America/New York timezone, but it seems this library is pulling in packages related to every other available timezone/locale.

Here is how we're currently using the library:

import tz from 'timezone'

const getESTHours = (date) => {
  const US = tz(require('timezone/America'))
  const currentESTHour = US(date, 'America/New_York', '%H')
  return parseInt(currentESTHour, 10)
}

And here's a screenshot of our bundle analysis, where the timezone module has contributed to a huge percentage of our bundle size.

screen shot 2017-12-14 at 8 34 00 am

We figured Webpack's tree shaking feature with UglifyJsPlugin would have automatically removed them if they were unused, but we wanted to drop a note here just in case anyone else has run into this before.

Any help would be super appreciated! ✊

@leedstyh
Copy link

leedstyh commented Dec 29, 2017

The bundle size is too big for me too, but I also need them as the user can switch timezone in my app. So import them dynamically as needed is a better choice?

@webschik
Copy link

@bteng22 , did you try to include a timezone in the next way?

import tz from 'timezone'

const getESTHours = (date) => {
  const US = tz(require('timezone/America/New_York')); // include only your specific timezone
  const currentESTHour = US(date, 'America/New_York', '%H')
  return parseInt(currentESTHour, 10)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants