{"id":18959,"library":"antd-dayjs-webpack-plugin","title":"antd-dayjs-webpack-plugin","description":"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.","status":"active","version":"1.0.6","language":"javascript","source_language":"en","source_url":"https://github.com/ant-design/antd-dayjs-webpack-plugin","tags":["javascript","Day.js","Webpack","Moment","antd"],"install":[{"cmd":"npm install antd-dayjs-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add antd-dayjs-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add antd-dayjs-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency — required at runtime for the replacement to work.","package":"dayjs","optional":false}],"imports":[{"note":"CommonJS module — default export, cannot use ESM import directly. Works with webpack config files.","wrong":"import AntdDayjsWebpackPlugin from 'antd-dayjs-webpack-plugin';","symbol":"AntdDayjsWebpackPlugin","correct":"const AntdDayjsWebpackPlugin = require('antd-dayjs-webpack-plugin');"},{"note":"Since v1.0.0, the package changed default export to a named plugin. Using require directly gives the plugin function, not an object with .default. This is the correct way to get the default export if you treat it as ESM.","wrong":"const AntdDayjsWebpackPlugin = require('antd-dayjs-webpack-plugin');","symbol":"default","correct":"const AntdDayjsWebpackPlugin = require('antd-dayjs-webpack-plugin').default;"},{"note":"Must instantiate the plugin with 'new' — passing the class reference directly will not work.","wrong":"plugins: [AntdDayjsWebpackPlugin]","symbol":"new AntdDayjsWebpackPlugin()","correct":"plugins: [new AntdDayjsWebpackPlugin()]"}],"quickstart":{"code":"// webpack.config.js\nconst AntdDayjsWebpackPlugin = require('antd-dayjs-webpack-plugin');\n\nmodule.exports = {\n  // ...\n  plugins: [\n    new AntdDayjsWebpackPlugin()\n  ]\n};\n\n// Install dayjs: npm install dayjs\n// Import dayjs and set locale in your app entry\nimport dayjs from 'dayjs';\nimport 'dayjs/locale/zh-cn';\ndayjs.locale('zh-cn');","lang":"javascript","description":"Shows minimal webpack config to replace Moment.js with Day.js in Ant Design projects, including locale setup."},"warnings":[{"fix":"Upgrade webpack to 4+ or use an older version of this plugin.","message":"Plugin requires webpack 4+ and Node >=8. Older webpack versions are not supported.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Set replaceMoment: true explicitly if needed, or rely on default.","message":"The 'replaceMoment' option defaults to true. In future versions, this may be removed or changed.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Consider upgrading to antd 4+ to avoid using the antdv3 preset. If you must use antd 3, handle Day.js objects as mutable.","message":"Using 'antdv3' preset enables BadMutable plugin, making Day.js mutable. This can cause unexpected mutations.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Manually alias moment to dayjs in webpack resolve.alias if needed, but be cautious of API differences.","message":"The plugin does not replace moment in node_modules other than antd. Third-party libraries using moment directly will still have moment bundled.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run npm install antd-dayjs-webpack-plugin --save-dev","cause":"Missing installation of the plugin.","error":"Cannot find module 'antd-dayjs-webpack-plugin'"},{"fix":"Use const AntdDayjsWebpackPlugin = require('antd-dayjs-webpack-plugin');","cause":"Using default import instead of require in CJS context.","error":"TypeError: AntdDayjsWebpackPlugin is not a constructor"},{"fix":"Use require() or ensure your webpack config supports ESM. The package exports a CommonJS module.","cause":"Trying to import the plugin in an ES module file that webpack processes as CJS (e.g., .js file with import statements).","error":"Module parse failed: Unexpected token (1:0)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}