antd-dayjs-webpack-plugin

raw JSON →
1.0.6 verified Sat Apr 25 auth: no javascript

A webpack plugin that replaces Moment.js with Day.js in Ant Design projects, reducing bundle size from ~65 KB gzipped to ~4 KB. Version 1.0.6 is stable with no recent updates. Key differentiator: single-step integration without manual code changes. Requires dayjs as a peer dependency and supports Ant Design 3.x via 'antdv3' preset, which introduces a mutable Day.js (BadMutable plugin). Commonly used to slim down antd-based React apps.

error Cannot find module 'antd-dayjs-webpack-plugin'
cause Missing installation of the plugin.
fix
Run npm install antd-dayjs-webpack-plugin --save-dev
error TypeError: AntdDayjsWebpackPlugin is not a constructor
cause Using default import instead of require in CJS context.
fix
Use const AntdDayjsWebpackPlugin = require('antd-dayjs-webpack-plugin');
error Module parse failed: Unexpected token (1:0)
cause Trying to import the plugin in an ES module file that webpack processes as CJS (e.g., .js file with import statements).
fix
Use require() or ensure your webpack config supports ESM. The package exports a CommonJS module.
breaking Plugin requires webpack 4+ and Node >=8. Older webpack versions are not supported.
fix Upgrade webpack to 4+ or use an older version of this plugin.
deprecated The 'replaceMoment' option defaults to true. In future versions, this may be removed or changed.
fix Set replaceMoment: true explicitly if needed, or rely on default.
gotcha Using 'antdv3' preset enables BadMutable plugin, making Day.js mutable. This can cause unexpected mutations.
fix Consider upgrading to antd 4+ to avoid using the antdv3 preset. If you must use antd 3, handle Day.js objects as mutable.
gotcha The plugin does not replace moment in node_modules other than antd. Third-party libraries using moment directly will still have moment bundled.
fix Manually alias moment to dayjs in webpack resolve.alias if needed, but be cautious of API differences.
npm install antd-dayjs-webpack-plugin
yarn add antd-dayjs-webpack-plugin
pnpm add antd-dayjs-webpack-plugin

Shows minimal webpack config to replace Moment.js with Day.js in Ant Design projects, including locale setup.

// webpack.config.js
const AntdDayjsWebpackPlugin = require('antd-dayjs-webpack-plugin');

module.exports = {
  // ...
  plugins: [
    new AntdDayjsWebpackPlugin()
  ]
};

// Install dayjs: npm install dayjs
// Import dayjs and set locale in your app entry
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
dayjs.locale('zh-cn');