DEV Community

Discussion on: 5 steps to change antd theme on runtime using create-react-app

Collapse
marklyck profile image
Mark Lyck • Edited on

@andrei this guide no longer works :(

following the guide precisely first produces the following dependency errors:
Cannot find module 'mini-css-extract-plugin'
Cannot find module 'style-loader'

this is solved easily by installing the above devDependencies as well.

After this step, create-react-app can now start without errors.

the antd default theme is applied (I guess through the webpack plugin since nothing is imported and it doesn't change if I change import in vars.less)

window.less does exist and i can run modifyVars.

But trying to change any variables does not work.

Tried both with webpack@4 and webpack@5

Collapse
christianandrei profile image
Christian Andrei Author • Edited on

Thanks for the feedback! I guess some updates make this no longer works. I will look at it at my spare time. However you can clone the repo and install the packages that I provided for the meantime.

Collapse
marklyck profile image
Mark Lyck

Thanks for the quick reply!

I tried installing the specific versions of babel-import-plugin, less & less-loader used there, and I was able to update the color when running in development mode.

Adding some additional fixes around mini-css-extract plugin solved that.

But when going to the next step to attempt updating between light & dark theme. Everything broke again :(

I've been trying to find a solution to switch between light and dark antd theme for over a week now and everything I have tried in a vanilla create-react-app has failed.

Every guide I can find was on an older version of react-scripts and seems like there have been breaking changes :(.

Thread Thread
christianandrei profile image
Christian Andrei Author • Edited on

I feel you. That antd theming is very hard to achieved. I've been also there scratching my head over a week just to modify the colors of antd as well as switching it between light and dark colors. But don't lose hope! I've manage to do that. For me, this is one of the most interested part of being a developer, creating/exploring rare things.

You can check my work here. If that is what you need, I am very glad to share it with you and just play with it.

I have plan to create a blog about switching between light and dark theme (2021) in antd soon.

Thread Thread
marklyck profile image
Mark Lyck

Yes everything I need is in that boilerplate! Do you have a working repo for this?

🙏 would love to see an updated blog post on this compatible the latest version of create-react-app. 🙏🙏🙏

Thread Thread
christianandrei profile image
Christian Andrei Author

Yes there's a working repo but its private. That boilerplate is not fully perfect ready for big projects but good enough on small projects.. You can give me an email so I can send it to you.

Thread Thread
marklyck profile image
Mark Lyck • Edited on

That would be amazing 😁🙏

Thread Thread
christianandrei profile image
Christian Andrei Author

Sent! Hope that works on you. Happy coding!

Thread Thread
marklyck profile image
Mark Lyck • Edited on

@andrei , I don't think. I got an email or invitation 🤔

Thread Thread
christianandrei profile image
Christian Andrei Author • Edited on

I got Failure Notice maybe its block due to .js files.

Thread Thread
marklyck profile image
Mark Lyck

🤔 that's definitely the correct email.

Maybe it was full? I tried deleting a few thousand emails from it. Could you try one more time? Sorry!!!

Thread Thread
christianandrei profile image
Christian Andrei Author

Check your email. I shared it from gdrive.

Thread Thread
marklyck profile image
Mark Lyck

Got i! Thank you so much! 🙏

Thread Thread
ishantgupta777 profile image
Ishant Gupta

@christianandrei @marklyck I was trying for a long time to do this, but the instructions in blog are no longer working. Can anyone of you please share the boilerplate with me as well. I really need that and it'll be really helpful. Also @christianandrei the blog was really great, whenever you're free and think of updating it, I'm sure it'll really help alot of people includig me. Thanks.