Vite plugin that automatically converts Day.js CommonJS imports to ESM format for better tree-shaking and smaller bundle sizes. Current version 1.0.2 ships TypeScript types and works with all Day.js plugins and locales. Unlike manual import rewriting, this plugin provides zero-config conversion of dayjs, dayjs/plugin/*, and dayjs/locale/* imports to their ESM counterparts (dayjs/esm/...). It addresses the common footgun where Day.js CJS modules cannot be tree-shaken in Vite builds, leading to larger bundles. The plugin is maintained as part of the antdv-next ecosystem.
npm install vite-plugin-dayjsVerified import paths — ran on the pinned version, not inferred.
Configures vite-plugin-dayjs in vite.config.ts and demonstrates automatic ESM conversion of dayjs, plugin, and locale imports.
Use Vite as your build tool if you want to use this plugin.
For custom import handling, consider using vite-plugin-optimizer or patch-package with manual aliasing.
Ensure all dayjs usage in your source code uses import statements; consider using optimizeDeps to pre-bundle dependent CJS packages.
Install dayjs: npm install dayjs. Ensure dayjs version is >=1.8 which includes ESM support.
Check available plugins at https://day.js.org/docs/en/plugin/plugin and use the correct name (e.g., 'relativeTime' not 'relativetime').
Ensure the plugin is called: import vitePluginDayjs from 'vite-plugin-dayjs'; plugins: [vitePluginDayjs()].
No dependency data recorded yet.