LESS and Ant Design integration without plugins, hooking into built-in Sass config #14847
Replies: 2 comments
-
Yes, the official plugin has expired and is no longer applicable to the new version of Next. js. You can try Since Next.js 9.3 supports If you use Next.js >
To solve the above problems, my idea is very simple.
This 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.. |
Beta Was this translation helpful? Give feedback.
-
It got error when using your snippet. error - ./node_modules/antd/lib/button/style/index.less 1:0
Module parse failed: Unexpected character '@' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> @import '../../style/themes/index';
| @import '../../style/mixins/index';
| @import './mixin'; Do you have any repo to test out ? Thanks. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I recently started working on a brand new project that was set on using Ant Design as a design guide and UI framework. I wanted to also use Next because I recently learned it and loved the ergonomics. Plus they were also set on going serverless so I thought it would be a good match. Oh boy... I mean, Next is awesome but its LESS integration is two years without an update and Ant Design doesn't help matters with its clunky architecture.
Anyhow, after weeks of fumbling around with it, having all kinds of issues, trying all kinds of solutions and reading A LOT of issues, including some Chinese ones (because Ant Design is Chinese) I managed something I thought would be impossible.
I'm sharing it here because I wanted to help other people going through the same struggle and also because I wanted to pique the attention of Next team. Please, if you read this, consider making integration with other CSS pre-processors a bit easier. 🙂
So, here's my
next.config.js
with unrelated parts removed:And also my
.babelrc
because, yes,babel-plugin-import
is still needed for Ant Design to work adequately.What I did was basically hook into Next config mid runtime and duplicate some of the Sass related options and edit it slightly to work with
.less
files and the LESS loader. I never imagined it would work so well. In development and production, SSR, static build/export, even@font-face
rules are working flawlessly without extra loaders. I'm so happy to put it behind me! 😊Well I hope it helps someone. If you have any questions about this or if I made some mistakes please let me know.
Beta Was this translation helpful? Give feedback.
All reactions