共计 644 个字符,预计需要花费 2 分钟才能阅读完成。
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>
)
}
}
正文完