Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

moment-timezone-loader

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

moment-timezone-loader

Webpack loader for moment-timezone that lets you cherry-pick the timezones you need

latest
npmnpm
Version
1.2.0
Version published
Maintainers
1
Created
Source

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

# Install moment-timezone if you haven't already
npm i moment-timezone
# Install this library
npm i -D moment-timezone-loader

Make Webpack use this loader whenever moment-timezone is imported

// webpack.config.js

module.exports = {
  // ...other stuff...
  module: {
    rules: [
      {
        test: /node_modules[\\/]moment-timezone[\\/]/,
        use: [{
          loader: 'moment-timezone-loader',
          options: {
            zones: [
              // List here all the timezones that you want included
              'Europe/Helsinki',
              'Europe/Stockholm',
            ]
          }
        }]
      }
    ]
  }
}

After that, you can import and use moment-timezone normally

import moment from 'moment-timezone'

// This will work because the timezone was included in our config
moment().tz('Europe/Helsinki')
// This will work because Europe/Mariehamn is in the same timezone
// as Europe/Helsinki and included in moment-timezone's "links" list.
moment().tz('Europe/Mariehamn')
// This will work because Etc/UTC is always included automatically.
moment().tc('UTC')
// This won't work because timezone definition for America/New_York
// wasn't included in the loader options. moment-timezone will log
// an error to the console.
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.

Keywords

webpack

FAQs

Package last updated on 26 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts