微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

create-react-app设置全局less和模块less

官网链接https://ant.design/docs/react/use-with-create-react-app-cn

将craco.config.js文件里的内容添加less模块配置就可以使用

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

module.exports = {
  plugins: [
    {
      plugin: CracoLessplugin,
      options: {
        //添加cssLoaderOptions代表模块化,不添加代表全局
        cssLoaderOptions:{
            modules:{
                localIdentName: "[local]_[hash:base64:5]",
            }
            
        },
        lessLoaderOptions: {
        
          lessOptions: {
            modifyVars: { '@primary-color': '#1DA57A' },
            javascriptEnabled: true,
          },
        },
      },
    },
  ],
};

当为模块化less时就需要按模块引入然后使用

import style from './App.less';

function App() {
  return (
    <div className={style.App}>
        <h1>我是和</h1>
    </div>
  );
}

export default App;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐