prantlf / timezone-support

Lightweight time zone support for your applications or other date libraries.
MIT License
117 stars 28 forks source link

Weird bundle size in production #14

Open sergio-bravo opened 5 years ago

sergio-bravo commented 5 years ago

Hi. In readme it's said:

Tiny code base - 4.6 KB minified, 1.7 KB gzipped...

In my project I see different picture: image

I use it via date-fns-timezone: ^0.1.4

sergio-bravo commented 5 years ago

Update: Probably it worth a mention in readme that timezone-support requires tree-shaking to be configured.

Pagebakers commented 5 years ago

@sergio-bravo Do you have an example how to get this working with webpack and date-fns-timezone?

AndriiDidkivsky commented 5 years ago

Any updates ? How can i exclude unused timezones ?

Pagebakers commented 5 years ago

Webpack config

  resolve: {
    extensions: ['*', '.js', '.jsx'],
    alias: {
      'timezone-support$': path.join(__dirname, 'node_modules/timezone-support/dist/index-2012-2022.js')
    }
}
sergio-bravo commented 5 years ago

@Pagebakers sorry I only saw the question now.

I used webpack tree-shaking guide, not alias

As I can remember it was done in .babelrc

"presets": [["@babel/preset-env", { "modules": false }]]

and `package.json``

"sideEffects": false,
Pagebakers commented 5 years ago

No worries :)

Thanks, this is what I tried at first but it always seemed to include the full timezone database.

mattdodge commented 5 years ago

I'm having the same issue as the OP. Using this library via date-fns-timezone and getting nearly 1 MB of timezone-support in my production build. I'm building via next.js. Anyone find a fix for this yet?

houmark commented 5 years ago

I'm seeing the same picture and not sure if any of the above mentioned solutions works to bring down the final bundle size? I am using webpack through create-react-app.

Pagebakers commented 5 years ago

My suggested webpack config works perfect for me.

You could even copy the index-2012-2022.js list and strip out even more relevant data to decrease the size.

houmark commented 5 years ago

It's just that my webpack config is completely vanilla, I have not had the need to do any custom configurations at all to all my packages as they all allow tree shaking — maybe a few do not, but they are so small that the gain would be negligible.

This package should do this out of the box really — especially due to its large size.

I'll try it out, thanks!