react配置 less antd

本文详细介绍如何在React项目中集成Ant Design UI框架,并配置Less预处理器,包括React脚手架安装、Yarn使用、React生命周期说明、所需插件安装、Ant Design安装及配置、Webpack配置、Less配置等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

react配置 less antd

一、react脚手架安装

  1. 全局安装
npm install -g create-react-app
  1. 创建react app
create-react-app 项目名称

二、安装 yarn

npm install -g yarn

yarn使用:

  • yarn init
  • yarn add
  • yarn remove
  • yarn install

react生命周期

getDefaultProps 
getInitialState 
componentWillMount 
render
componentDidMount
componentReceiveProps 
shouldComponentUpdate
componentWilUpdate
componentDidUpdate
componentWilUnmount

三、安装所需插件

  • 安装React-Router 、Axios、less-loader
yarn add react-router-dom axios less less-loader
  • 配置less

    • 暴露webpack

    • yarn eject
    • 修改config目录下的webpack.config.dev.js和webpack.config.prod.js文件

    • 快速定位:查找这两个文件的use数组,在数组里面添加添加,

    • //上面的css改为
      test: /\.(css|less)$/,
      
      //use数组后面添加
      {
          loader: require.resolve('less-loader'),
          //antd主题设置
          options: {
              modules:false,
              modifyVars:{
              "@primary-color":"#f9c700"
              }
           }
      }

      在use数组上面css改为

      test: /\.(css|less)$/,

      webpack.config.dev.js和webpack.config.prod.js两个文件的配置一样

四、安装antd

yarn add antd

安装babel插件

yarn add babel-plugin-import --dev

按需加载antd组件,快速定位: 查找limit或10000,在下面的options对象添加

plugins:[
          ['import',[{libraryName:'antd',style:true}]]
        ],
        //因为要修改源码样式,这里的style配置为true

webpack.config.prod.js修改

可能会报错
  • 降低less版本
yarn add less@^2.7.3
yarn add moment --save

安装jsonp

yarn add jsonp --save

遇到的坑

  • 状态吗不能用全等
  • 表格必须有一个key值,通过map循环获取
data.map((item,index)=>{
  item.key=index
})

转载于:https://www.cnblogs.com/dobeco/p/11295178.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值