2

image.png

cnpm i react-app-rewired customize-cra babel-plugin-import -D

根目录新建config-overrides.js

const {override,fixBabelImports} = require('customize-cra') // override返回一个函数   该函数返回对象作为webpack的配置对象 module.exports = override( fixBabelImports("import",{ libraryName:'antd',  //库名 libraryDirectory:'es', //文件夹名 style:'css'  //一个叫css.js的文件 }) )

package.json

script改成 "scripts": { "start": "react-app-rewired start", "build": "react-app-rewired build", "test": "react-app-rewired test", "eject": "react-app-rewired eject" },

使用

import React, { Component } from 'react' import {Button} from 'antd' export default class Text extends Component { render() { return ( <div> <Button type="primary">BUtton</Button> </div> ) } }

HappyCodingTop
526 声望847 粉丝

Talk is cheap, show the code!!


« 上一篇
React高阶组件
下一篇 »
React的Hooks