{"id":15492,"library":"vite-plugin-moment-timezone","title":"Vite Plugin for Moment Timezone Data Optimization","description":"vite-plugin-moment-timezone is a Vite plugin designed to optimize bundle size by selectively stripping unneeded time zone data from the `moment-timezone` library during the build phase. This is particularly useful for applications that only require a subset of time zones or a specific date range, as `moment-timezone` can be quite large. The current stable version is 0.0.4. Given its low version number and explicit mention of \"extremely limited testing\" and being \"new,\" it does not yet have a predictable release cadence and should be used with caution, thoroughly testing builds before deployment. Its key differentiator is providing build-time tree-shaking for `moment-timezone` data within a Vite environment, allowing configuration of `zones`, `startYear`, and `endYear` to significantly reduce the final JavaScript bundle size compared to including all available `moment-timezone` data.","status":"active","version":"0.0.4","language":"javascript","source_language":"en","source_url":"https://github.com/cbetori/vite-plugin-moment-timezone","tags":["javascript","vite","vite plugin","vitejs","vitejs plugin","vite-plugin","moment","moment-timezone","timezone","typescript"],"install":[{"cmd":"npm install vite-plugin-moment-timezone","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-moment-timezone","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-moment-timezone","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This is a peer dependency that the plugin modifies and optimizes. It must be installed separately in the project.","package":"moment-timezone","optional":false}],"imports":[{"note":"This plugin is designed for ESM environments like Vite and typically imported as a default export.","wrong":"const momentTimezonePlugin = require('vite-plugin-moment-timezone');","symbol":"momentTimezonePlugin","correct":"import momentTimezonePlugin from 'vite-plugin-moment-timezone';"},{"note":"While not directly from this package, `UserConfig` is a common type import when configuring Vite plugins with TypeScript.","symbol":"UserConfig","correct":"import { defineConfig, type UserConfig } from 'vite';"}],"quickstart":{"code":"import { defineConfig } from 'vite';\nimport momentTimezonePlugin from 'vite-plugin-moment-timezone';\n\nexport default defineConfig({\n  plugins: [\n    momentTimezonePlugin({\n      zones: ['America/Los_Angeles', 'Europe/London'],\n      startYear: 2020,\n      endYear: 2025\n    }),\n  ],\n  build: {\n    // Example of a common Vite build setting, not directly related to the plugin but good context\n    minify: 'esbuild',\n    sourcemap: true,\n  },\n});","lang":"javascript","description":"Demonstrates how to install and configure the plugin in a Vite project to include specific time zones and year ranges."},"warnings":[{"fix":"Thoroughly test your application's build output and runtime behavior in various environments before deploying to production.","message":"The plugin explicitly states \"extremely limited testing\" and is a new project. Production deployments should proceed with caution and thorough testing.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Always test your final production build artifact to ensure `moment-timezone` data is correctly stripped and your application functions as expected.","message":"This plugin only runs during the build phase. Any `moment-timezone` data manipulation or loading behavior observed in development mode might differ from the production build.","severity":"breaking","affected_versions":">=0.0.1"},{"fix":"Ensure your project uses Node.js 20, Vite 5, and `moment-timezone` v0.5.0+ to maintain compatibility with the tested environment.","message":"The plugin has only been tested with Node.js 20, Vite 5, and moment-timezone v0.5.0 or higher. Using older or significantly newer versions of these dependencies may lead to unexpected behavior or build failures.","severity":"breaking","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Run `npm install moment-timezone` or `yarn add moment-timezone` in your project.","cause":"The `moment-timezone` package is a peer dependency and must be installed separately.","error":"Error: Cannot find module 'moment-timezone'"},{"fix":"Verify that `import momentTimezonePlugin from 'vite-plugin-moment-timezone';` is present and the plugin is added to the `plugins` array, e.g., `plugins: [momentTimezonePlugin({ ... })]`.","cause":"The `momentTimezonePlugin` was not correctly imported or included in the `plugins` array in `vite.config.js`.","error":"TypeError: Cannot read properties of undefined (reading 'plugins')"}],"ecosystem":"npm"}