Skip to content

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

@MaxDNG

Description

@MaxDNG

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions