Moment-timezone: Tree shaking not working

Created on 24 Jul 2017  路  4Comments  路  Source: moment/moment-timezone

Is there any benefit to doing:

import { tz } from 'moment-timezone';

...

tz(...);

Instead of:

import * as Moment from 'moment-timezone';

...

Moment.tz(...);

It seems like importing only the relevant functions should allow Webpack tree shaking to reduce bundle size but I'm not noticing any difference. Does Moment support tree shaking?

Most helpful comment

Hello,

I've stumbled across same problem, anyone found a workaround?

All 4 comments

The _vast_ majority of the size of moment timezone is all within the single latest.json file contained in one object. There is no immediately apparent way to select out of that just the locales that are relevant to you.

Hello,

I've stumbled across same problem, anyone found a workaround?

Shameless self-promotion here, but I've just built a webpack plugin to reduce how much data is loaded when using moment-timezone: https://github.com/gilmoreorless/moment-timezone-data-webpack-plugin

The zones and year ranges for the data are configurable, so you can include as much or as little data as you need.

You can also do this:
import moment from 'moment-timezone/builds/moment-timezone-with-data-2012-2022.min'

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Liero picture Liero  路  4Comments

SathyaChenniappan picture SathyaChenniappan  路  4Comments

palindrom615 picture palindrom615  路  4Comments

rjpedrosa picture rjpedrosa  路  5Comments

GMeulendyks picture GMeulendyks  路  5Comments