react antd使用
npm i antd --save
全局引入
import React, { Component } from 'react' import Button from 'antd/lib/button' import 'antd/dist/antd.css' export default class App1 extends Component { render() { return ( <div> <h1>演示antd组件库的使用</h1> <Button type="primary">按钮</Button> </div> ) } }
- 安装命令yarn add react-app-rewired customizecra(如果还没安装yarn的可以先执⾏npm install yarn -g进⾏安装
- 更改package.json⽂件
/* 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",}
- 然后在项⽬根⽬录创建⼀个 config-overrides.js ⽤于修改默认配置,先不⽤写内容
- 执⾏安装 babel-plugin-import插件(安装命令:yarn addbabel-plugin-import)
- 修改config-overrides.js⽂件内容如下:
const { override, fixBabelImports } = require('customize-cra');
module.exports = override( fixBabelImports('import', {
libraryName: 'antd', libraryDirectory: 'es', style: 'css',
}), );
本文来自博客园,作者:zjxgdq,转载请注明原文链接:https://www.cnblogs.com/zjxzhj/p/15114548.html