Vite Plugin for Moment Timezone Data Optimization

0.0.4 · active · verified Tue Apr 21

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.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to install and configure the plugin in a Vite project to include specific time zones and year ranges.

import { defineConfig } from 'vite';
import momentTimezonePlugin from 'vite-plugin-moment-timezone';

export default defineConfig({
  plugins: [
    momentTimezonePlugin({
      zones: ['America/Los_Angeles', 'Europe/London'],
      startYear: 2020,
      endYear: 2025
    }),
  ],
  build: {
    // Example of a common Vite build setting, not directly related to the plugin but good context
    minify: 'esbuild',
    sourcemap: true,
  },
});

view raw JSON →