Webpack loader for moment-timezone that allows you to
pick and choose just the timezones you need, resulting in smaller bundle sizes.
Installation and usage
npm i moment-timezone
npm i -D moment-timezone-loader
Make Webpack use this loader whenever moment-timezone is imported
module.exports = {
module: {
rules: [
{
test: /node_modules[\\/]moment-timezone[\\/]/,
use: [{
loader: 'moment-timezone-loader',
options: {
zones: [
'Europe/Helsinki',
'Europe/Stockholm',
]
}
}]
}
]
}
}
After that, you can import and use moment-timezone normally
import moment from 'moment-timezone'
moment().tz('Europe/Helsinki')
moment().tz('Europe/Mariehamn')
moment().tc('UTC')
moment().tc('America/New_York')
The timezones are taken from this json file
in the moment-timezone version you are using. Timezone Etc/UTC is always included and doesn't
need to be explicitly specified in the zones-option.