timezone-support icon indicating copy to clipboard operation
timezone-support copied to clipboard

Weird bundle size in production

Open sergio-bravo opened this issue 6 years ago • 10 comments

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 avatar Jul 09 '19 13:07 sergio-bravo

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

sergio-bravo avatar Jul 09 '19 15:07 sergio-bravo

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

Pagebakers avatar Aug 29 '19 09:08 Pagebakers

Any updates ? How can i exclude unused timezones ?

AndriiDidkivsky avatar Nov 07 '19 16:11 AndriiDidkivsky

Webpack config

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

Pagebakers avatar Nov 07 '19 20:11 Pagebakers

@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,

sergio-bravo avatar Nov 08 '19 08:11 sergio-bravo

No worries :)

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

Pagebakers avatar Nov 08 '19 08:11 Pagebakers

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?

mattdodge avatar Nov 19 '19 04:11 mattdodge

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.

houmark avatar Nov 21 '19 21:11 houmark

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.

Pagebakers avatar Nov 22 '19 07:11 Pagebakers

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!

houmark avatar Nov 22 '19 07:11 houmark