Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use custom vars in .less root file #100

Open
MaxDNG opened this issue Jul 4, 2022 · 1 comment
Open

Unable to use custom vars in .less root file #100

MaxDNG opened this issue Jul 4, 2022 · 1 comment

Comments

@MaxDNG
Copy link

MaxDNG commented Jul 4, 2022

Hi all,

I have been using craco-antd for our app and recently I started having issues with less compilation.
Basically, it generates two copies of the antd css, one with my custom colours, one with the default. The default being generated last, it overrides my custom settings.
image

The way I have been doing it so far might not be canonical but I needed to do it like that. Here is what I have in the less root file

@import 'antd/dist/antd.less';

@link-color: #ff0000;
@primary-color: #00ff00;

This used to work fine until recently. Maybe linked to upgrade to craco-less 2.0 but not sure.

What is weird is that if I use craco-less instead, it works fine.
To be clear, this works:

const CracoLessPlugin = require('craco-less');

module.exports = function cracoConfig({ env }) {
  return {
    plugins: [
      {
        plugin: CracoLessPlugin,
        options: {
          lessLoaderOptions: {
            lessOptions: {
              javascriptEnabled: true,
            },
          },
        },
      },
    ],
  };
};

But this fails:

const CracoAntDesignPlugin = require('craco-antd');

module.exports = function cracoConfig({ env }) {
  return {
    plugins: [
      {
        plugin: CracoAntDesignPlugin,
        options: {
          lessLoaderOptions: {
            lessOptions: {
              javascriptEnabled: true,
            },
          },
        },
      },
    ],
  };
};

Here is a small reproduction repo from a brand new create-react-app: https://github.com/MaxDNG/craco-antd-issue

I try to find the issue but did not succeed so far. Will keep looking later on.

@Laguigue
Copy link

Laguigue commented Nov 8, 2022

I had the exact same problem, and this is how i just fixed it:

I found out that, somehow, in addition to importing the antd.less file into my root file App.less, I was also importing 'antd/dist/antd.css' 'inside of one of my react component. It was obviously a mystake so i got rid of it, and it started to work fine again. Search for any import of antd/dist/antd.css you might have made, maybe you did the same mystake as i did.

Edit: you can then use craco-antd instead of craco-less

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants