{"library":"moment-timezone-data-webpack-plugin","title":"Moment Timezone Data Webpack Plugin","description":"This webpack plugin, `moment-timezone-data-webpack-plugin`, is designed to significantly reduce the bundle size of `moment-timezone` by selectively stripping unneeded time zone data during the webpack build process. As of version 1.5.1, it provides critical functionality for applications that use `moment-timezone` but don't require its entire historical and global dataset, which can be over 900KiB raw. The plugin actively processes the `moment-timezone` data module, allowing developers to specify date ranges (e.g., `startYear`, `endYear`), specific zones via regular expressions (`matchZones`), or countries (`matchCountries`). This addresses a common issue where `moment-timezone` includes all data by default in webpack builds, even if runtime configuration limits the data usage. The plugin is in active maintenance, with recent updates ensuring compatibility with NodeJS 18 and Webpack 5. It works complementarily with `moment-locales-webpack-plugin` for further bundle size optimizations.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install moment-timezone-data-webpack-plugin"],"cli":null},"imports":["const MomentTimezoneDataPlugin = require('moment-timezone-data-webpack-plugin');","import MomentTimezoneDataPlugin from 'moment-timezone-data-webpack-plugin';","plugins: [new MomentTimezoneDataPlugin({ /* options */ })]"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import path from 'path';\nimport { Configuration } from 'webpack';\nimport MomentTimezoneDataPlugin from 'moment-timezone-data-webpack-plugin';\n\nconst config: Configuration = {\n  mode: 'production',\n  entry: './src/index.ts', // Assuming a simple entry point\n  output: {\n    path: path.resolve(__dirname, 'dist'),\n    filename: 'bundle.js',\n  },\n  module: {\n    rules: [\n      {\n        test: /\\.ts$/,\n        use: 'ts-loader',\n        exclude: /node_modules/,\n      },\n    ],\n  },\n  resolve: {\n    extensions: ['.ts', '.js'],\n  },\n  plugins: [\n    // This example limits timezone data to specific years and only for zones matching 'Europe/'\n    // and also includes all zones for 'AU' (Australia).\n    // It's crucial to ensure these settings cover all needed timezones for your application.\n    new MomentTimezoneDataPlugin({\n      startYear: 2020,\n      endYear: 2030,\n      matchZones: /Europe\\//, // Only include zones matching 'Europe/'\n      matchCountries: ['AU'], // Include all zones for Australia\n      cacheDir: path.resolve(__dirname, '.moment-timezone-cache') // Optional: custom cache directory\n    }),\n    // Optionally, if also stripping locales\n    // new MomentLocalesWebpackPlugin({\n    //   localesToKeep: ['en', 'es'],\n    // }),\n  ],\n};\n\nexport default config;\n","lang":"typescript","description":"This Webpack configuration demonstrates how to integrate `moment-timezone-data-webpack-plugin` to filter timezone data. It sets a date range (2020-2030), includes zones starting with 'Europe/', and all zones for Australia, significantly reducing the bundled `moment-timezone` data size.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}