{"id":14990537,"url":"https://github.com/solidzoro/next-plugin-antd-less","last_synced_at":"2025-05-16T14:07:13.828Z","repository":{"id":38355125,"uuid":"285228579","full_name":"SolidZORO/next-plugin-antd-less","owner":"SolidZORO","description":"🎩 Use Antd (Less) with Next.js v12, Zero Dependency on other Next-Plugins.","archived":false,"fork":false,"pushed_at":"2022-12-08T03:33:42.000Z","size":378,"stargazers_count":343,"open_issues_count":10,"forks_count":48,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-05T09:36:53.906Z","etag":null,"topics":["ant-design","antd","antd-design-pro","antd-less","antdpro","cra","craco","css-modules","less","next-plugin","next-plugins","nextjs","react"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SolidZORO.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-05T08:31:32.000Z","updated_at":"2025-02-22T23:44:37.000Z","dependencies_parsed_at":"2023-01-24T08:05:14.665Z","dependency_job_id":null,"html_url":"https://github.com/SolidZORO/next-plugin-antd-less","commit_stats":null,"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SolidZORO%2Fnext-plugin-antd-less","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SolidZORO%2Fnext-plugin-antd-less/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SolidZORO%2Fnext-plugin-antd-less/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SolidZORO%2Fnext-plugin-antd-less/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SolidZORO","download_url":"https://codeload.github.com/SolidZORO/next-plugin-antd-less/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254488049,"owners_count":22079355,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ant-design","antd","antd-design-pro","antd-less","antdpro","cra","craco","css-modules","less","next-plugin","next-plugins","nextjs","react"],"created_at":"2024-09-24T14:20:18.902Z","updated_at":"2025-05-16T14:07:13.794Z","avatar_url":"https://github.com/SolidZORO.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Next.js + Antd (with Less)\n\n[![version][npm-img]][npm-url]\n[![license][mit-img]][mit-url]\n[![size][size-img]][size-url]\n[![download][download-img]][download-url]\n\nUse [Antd] (Less) w/ [Next.js], Zero Dependency on other Next-Plugins.\n\n\n## Demo\n\n[Demo w/ Next.js v12](https://mkn.vercel.app/) by [mkn](https://github.com/SolidZORO/mkn)\n\n[Demo w/ CRA v5](https://mkr.vercel.app/) by [mkr](https://github.com/SolidZORO/mkr)\n\nYep! this plugin supports both [Next.js] and [CRA] since v1.0.\n\n\n## Features\n\n- Zero Dependency on other [Next.js] Plugins\n- Support Both [Next.js] \u0026 [CRA] Project\n- Support Hot-Update After modifying [Antd] less vars\n- Support Serverless Mode\n- Support Antd Pro\n\n## Compatibility\n\n- Next.js v11 / v12\n- CRA v4 / v5\n\n\n## Installation\n\n```sh\nyarn add next-plugin-antd-less\nyarn add --dev babel-plugin-import\n```\n\n\n## Usage\n\n### for [Next.js]\n\n```js\n// next.config.js\nconst withAntdLess = require('next-plugin-antd-less');\n\nmodule.exports = withAntdLess({\n  modifyVars: { '@primary-color': '#04f' }, // optional\n  lessVarsFilePath: './src/styles/variables.less', // optional \n  lessVarsFilePathAppendToEndOfContent: false, // optional\n  // optional https://github.com/webpack-contrib/css-loader#object\n  cssLoaderOptions: {\n    // ... \n    mode: \"local\",\n    localIdentName: __DEV__ ? \"[local]--[hash:base64:4]\" : \"[hash:base64:8]\", // invalid! for Unify getLocalIdent (Next.js / CRA), Cannot set it, but you can rewritten getLocalIdentFn\n    exportLocalsConvention: \"camelCase\",\n    exportOnlyLocals: false,\n    // ...\n    getLocalIdent: (context, localIdentName, localName, options) =\u003e {\n      return \"whatever_random_class_name\";\n    },\n  },\n\n  // for Next.js ONLY\n  nextjs: {\n    localIdentNameFollowDev: true, // default false, for easy to debug on PROD mode\n  },\n\n  // Other Config Here...\n\n  webpack(config) {\n    return config;\n  },\n\n  // ONLY for Next.js 10, if you use Next.js 11, delete this block\n  future: {\n    webpack5: true,\n  },\n});\n```\n\nAdd a `.babelrc.js`\n\n```js\n// .babelrc.js\nmodule.exports = {\n  presets: [['next/babel']],\n  plugins: [['import', { libraryName: 'antd', style: true }]],\n};\n```\n\nDetailed config can be found in [`next.config.js`](https://github.com/SolidZORO/mkn/blob/master/next.config.js)\nfile.\n\n### for [CRA] / [CRA-Co]\n\n```js\nconst cracoPluginLess = require('next-plugin-antd-less/overrideWebpackConfig');\n\nmodule.exports = {\n  babel: cracoBabel,\n  plugins: [\n    cracoPluginAnalyze,\n    {\n      plugin: cracoPluginLess,\n      options: {\n        modifyVars: {\n          '@THEME--DARK': 'theme-dark',\n        },\n        lessVarsFilePath: './src/styles/variables.less',\n        cssLoaderOptions: {\n          localIdentName: __DEV__ ? \"[local]--[hash:base64:4]\" : \"[hash:base64:8]\",\n        },\n      },\n    },\n  ],\n};\n```\n\nDetailed config can be found in [`craco.config.js`](https://github.com/SolidZORO/mkr/blob/master/scripts/craco/craco-plugin--less.js)\nfile.\n\n\n## FAQ\n\n### Reference Project?\n\nIf you have any problem, please check [mkn](https://github.com/SolidZORO/mkn) (Next.js)\nand [mkr](https://github.com/SolidZORO/mkr) (CRA) first, I update these two repo's every time I update this plugin.\n\n### Default ClassName\n\n| MODE      | className                  | e.g.                  |\n| --------- |----------------------------|-----------------------|\n| DEV       | `[local]--[hash:base64:4]` | `comp-wrapper--2Rra ` |\n| PROD      | `[hash:base64:8]`          | `2Rra8Ryx`            |\n\nfor Unify getLocalIdent (Next.js / CRA), Cannot set it, but you can rewritten getLocalIdentFn\n\n\n### localIdentName is invalid? How to rewritten?\n\nyou can defind your own `localIdentName` in `pluginOptions.cssLoaderOptions.modules.getLocalIdent`\n\n```javascript\n  options: {\n  lessVarsFilePath: './src/styles/variables.less'\n  // ...\n  // https://github.com/webpack-contrib/css-loader/tree/b7a84414fb3f6e6ff413cbbb7004fa74a78da331#getlocalident\n  //\n  // and you can see file \n  // https://github.com/SolidZORO/next-plugin-antd-less/getCssModuleLocalIdent.js\n  getLocalIdent: (context, _, exportName, options) =\u003e {\n    return 'whatever_random_class_name';\n  }\n  // ...\n}\n```\n\n### How to import global `CSS` style (e.g. styles.css)?\n\n```tsx\n// ./page/_app.tsx\n//\n// use `import` or `require` syntax,\nimport './styles.css';\n```\n\n### How to import global `Less` style (e.g. styles.less)?\n\n```tsx\n// ./page/_app.tsx\n//\n// use `require` syntax,\nrequire('./styles.less');\n```\n\n### How to overwrite `antd` less variables?\n\n```less\n// ./src/styles/variables.less\n@import '~antd/lib/style/themes/default.less'; // \u003c-- you need to import antd variables once in your project\n\n@primary-color: #04f; // change antd primary-color\n```\n\n\n```js\n// 🔰️ Tips: if your use babel import plugin and set `libraryDirectory`, please keep `libraryDirectory` and `less path` consistent.\n\n// lib\n['import', { libraryName: 'antd', libraryDirectory: 'lib', style: true }]\n// `@import '~antd/lib/style/themes/default.less';` \u003c-- use `lib`\n\n// es\n  ['import', { libraryName: 'antd', libraryDirectory: 'es', style: true }]\n// --\u003e `@import '~antd/es/style/themes/default.less';` \u003c-- use `es`\n```\n\n\n```js\n// plugin options\nlessVarsFilePath: './src/styles/variables.less'\n```\n\n@seeMore issues [#36](https://github.com/SolidZORO/next-plugin-antd-less/issues/36), [#74](https://github.com/SolidZORO/next-plugin-antd-less/issues/74)\n\n\n## Background\n\n### Issues\n\nSince Next.js 9.3 supports `sass` and `css` by default, but does not support `less`. If you use Next.js \u003e `9.3` and use the official less plugin, you will definitely encounter the following problems.\n\n1. CIL Warning `Warning: Built-in CSS support is being disabled due to custom CSS configuration being detected.`\n\n2. Does not support automatic recognition of css modules, e.g. `a.module.less`\n   and `a.less`\n\n### Solution\n\n1. Find sassModule and copy onec and replace the `sass-loader` inside with `less-loader`.\n\n2. Then enable the `modules.auto` option of `css-loader`. This can simply match all `*.less` (no need to match it is `*.module.less` or `*.less`), and hand it over to `css-loader`.\n\nThis is the lowest cost way, And CLI will no longer show this disgusting warning. The important thing is that there is **Zero Dependency on other Next-Plugins.**.\n\n\n## License\n\nMIT © [Jason Feng][author-url]\n\n\u003c!-- links --\u003e\n\n[Next.js]: https://nextjs.org/\n\n[Antd]: https://github.com/ant-design/ant-design/\n\n[CRA]: https://create-react-app.dev/\n\n[CRA-co]: https://github.com/gsoft-inc/craco\n\n\u003c!-- badges --\u003e\n\n[author-url]: https://github.com/SolidZORO\n\n[mit-img]: https://img.shields.io/npm/l/next-plugin-antd-less.svg?style=flat\u0026colorA=000000\u0026colorB=000000\n\n[mit-url]: ./LICENSE\n\n\n[npm-img]: https://img.shields.io/npm/v/next-plugin-antd-less?style=flat\u0026colorA=000000\u0026colorB=000000\n\n[npm-url]: https://www.npmjs.com/package/next-plugin-antd-less\n\n\n[size-img]: https://img.shields.io/bundlephobia/minzip/next-plugin-antd-less?label=bundle\u0026style=flat\u0026colorA=000000\u0026colorB=000000\n\n[size-url]: https://www.npmjs.com/package/next-plugin-antd-less\n\n\n[download-img]: https://img.shields.io/npm/dt/next-plugin-antd-less.svg?style=flat\u0026colorA=000000\u0026colorB=000000\n\n[download-url]: https://www.npmjs.com/package/next-plugin-antd-less\n\n\n[build-img]: https://img.shields.io/github/workflow/status/SolidZORO/next-plugin-antd-less/Lint?style=flat\u0026colorA=000000\u0026colorB=000000\n\n[build-url]: https://github.com/SolidZORO/next-plugin-antd-less/actions\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolidzoro%2Fnext-plugin-antd-less","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsolidzoro%2Fnext-plugin-antd-less","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolidzoro%2Fnext-plugin-antd-less/lists"}