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.
npm install moment-timezone-data-webpack-pluginVerified import paths — ran on the pinned version, not inferred.
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.
Carefully define `startYear`, `endYear`, `matchZones`, and `matchCountries` options. Consider a wider range or more zones if unsure, and use a staging environment for testing.
Upgrade your build environment to a supported Node.js version (e.g., Node.js 16 or newer) to ensure compatibility and receive official support.
Ensure `moment-timezone` (`>=0.1.0`) and `webpack` (`4.x.x` or `5.x.x`) are installed as peer dependencies or compatible versions in your project.
Always instantiate the plugin with `new MomentTimezoneDataPlugin({...})` in your webpack configuration file.Change `plugins: [MomentTimezoneDataPlugin({...})]` to `plugins: [new MomentTimezoneDataPlugin({...})]`.Install `moment-timezone` using `npm install moment-timezone` or `yarn add moment-timezone`.
Adjust the plugin options (`startYear`, `endYear`, `matchZones`, `matchCountries`) to include the necessary timezone data. Thoroughly test all time-related functionalities.
Verify that your `webpack` version (`4.x.x` or `5.x.x`) is compatible with the plugin version. Ensure `webpack` and `moment-timezone-data-webpack-plugin` are correctly installed and configured in your `package.json` and `webpack.config.js`.