zoukankan      html  css  js  c++  java
  • react+antd环境配置

    安装homebrew:
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    安装脚手架:npm install create-react-app
    安装yarn:brew install yarn
    创建项目:create-react-app react_item_name
    安装路由:yarn add react-router-dom
    安装axios:yarn add axios
    安装antd:yarn add antd
    启动项目:npm start

    按需引入antd

    1、yarn add react-app-rewired customize-cra

    /* package.json */
    "scripts": {
    -   "start": "react-scripts start",
    +   "start": "react-app-rewired start",
    -   "build": "react-scripts build",
    +   "build": "react-app-rewired build",
    -   "test": "react-scripts test",
    +   "test": "react-app-rewired test",
    }

    2、根目录下创建config-overrides.js

    module.exports = function override(config, env) {
      // do stuff with the webpack config...
      return config;
    };

    3、yarn add babel-plugin-import

    修改config-overrides.js文件:
    + const { override, fixBabelImports } = require('customize-cra'); - module.exports = function override(config, env) { - // do stuff with the webpack config... - return config; - }; + module.exports = override( + fixBabelImports('import', { + libraryName: 'antd', + libraryDirectory: 'es', + style: 'css', + }), + );

    这样就可以按需引入antd组件

    如:
     // src/App.js
      import React, { Component } from 'react';
    + import { Button } from 'antd';
      import './App.css';
    
      class App extends Component {
        render() {
          return (
            <div className="App">
              <Button type="primary">Button</Button>
            </div>
          );
        }
      }
    
      export default App;

    但有的时候需要使用less,如修改主题

    解决办法如下:

    1、yarn add less less-loader

    修改config-overrides.js文件:

    - const { override, fixBabelImports } = require('customize-cra'); + const { override, fixBabelImports, addLessLoader } = require('customize-cra'); module.exports = override( fixBabelImports('import', { libraryName: 'antd', libraryDirectory: 'es', - style: 'css', + style: true, }), + addLessLoader({ + javascriptEnabled: true, + modifyVars: { '@primary-color': '#1DA57A' }, + }), );

    测试:可以把app.css改成app.less;

      app.js中的引入app.css改成app.less

  • 相关阅读:
    Delphi常用内存管理函数
    delphi中VirtualStringTree树使用方法
    Delphi常量
    delphi中的copy函数和pos函数
    delphi 中 delete的用法
    字软元件和位软元件的区别
    Virtual Treeview使用要点
    QTreeWidget搜索功能---遍历QTreeWidget
    C 语言使用 sqlite3
    opendir 与 readdir
  • 原文地址:https://www.cnblogs.com/shui1993/p/10813303.html
Copyright © 2011-2022 走看看