Skip to content

module.less not work #56

@zdd

Description

@zdd

I want to use module.less in my app, but it doesn't work, the style was not applied. please help, this is my craco.config.js file:
craco-less version: 1.17.1

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

module.exports = {
  plugins: [
    {
      plugin: CracoLessPlugin,
      options: {
        lessLoaderOptions: {
          lessOptions: {
            modifyVars: { '@primary-color': '#004DE5' },
            javascriptEnabled: true,
          },
        },
        modifyLessRule: function(lessRule, _context) {
          lessRule.test = /\.(module)\.(less)$/;
          lessRule.exclude = /node_modules/;

          return lessRule;
        },
        cssLoaderOptions: {
          modules: { localIdentName: "[local]_[hash:base64:5]" }
        }
      }
    },
  ],
};

and this is my tsx and style file, they were in the same dir.
AppHeader.tsx
import './AppHeader.module.less'; // import style file

AppHeader.module.less

.site_layout_header {
  display: flex;
  align-items: center;
  height: 64px;
  padding: 0 8px;
  justify-content: space-between;
  background-color: @primary-color;
}

.site_logo {
  height: 58px;
  margin-left: 0;
  cursor: pointer;
  object-fit: contain;
}

.site_info {
  display: flex;
  align-items: center;
}

.site_user {
  margin-left: 8px;
  color: white;
}

.logout_button {
  margin-left: 8px;
  color: #FFF;
  padding: 0 20px;
  border: 1px solid #16D0FF;
  border-radius: 15px;
  font-size: 12px;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions