首页 > 其他 > 详细

react引入antd并配置按需加载和自定义主题

时间:2021-04-16 09:18:26      阅读:31      评论:0      收藏:0      [点我收藏+]
  1. 下载组件库包

    yarn add antd
    
  2. 使用craco对create-react-app进行自定义配置

    1. yarn add @craco/craco
      
    2. 根目录创建craco.config.js文件

      /* craco.config.js */
      module.exports = {
        // ...
      };
      
    3. 更改package.json

      "scripts": {
          "start": "craco start",
          "build": "craco build",
          "test": "craco test",
          "eject": "react-scripts eject"
        },
      
  3. 实现按需打包

    1. yarn add babel-plugin-import
      
    2. craco.config.js添加

      babel:{  
          plugins: [
            [   
              "import", 
              {
                "libraryName": "antd",
                "libraryDirectory": "es",
                 "style": true //设置为true即是less
               }
           ]
          ]
       }
      
  4. 实现自定义主题

    1. yarn add craco-less
      
    2. craco.config.js添加

      module.exports = {
          plugins: [{
              plugin: CracoLessPlugin,
              options: {
                  lessLoaderOptions: {
                      lessOptions: {
                          modifyVars: {
                              ‘@primary-color‘: ‘#1DA57A‘
                          },
                          javascriptEnabled: true,
                      },
                  },
              },
          },],
      };
      

react引入antd并配置按需加载和自定义主题

原文:https://www.cnblogs.com/bleso/p/14665292.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!