按照官网的做法做了很久都没找到头绪,而且各种报错, react-app-rewired的版本也无法使用
后来找到的解决办法,参照https://blog.csdn.net/guo187/article/details/93209335
步骤如下:
1.引入 react-app-rewired 并修改 package.json 里的启动配置。。由于新的 react-app-rewired@2.x 版本的关系,你需要还需要安装 customize-cra。
$ npm install react-app-rewired customize-cra --save-dev
2.修改package.json 中scripts为下面内容, /* package.json */
"scripts": {
"start":"react-app-rewired start",
"build":"react-app-rewired build",
"test":"react-app-rewired test --env=jsdom",
"eject":"react-scripts eject"
}
3.在package.json中添加以下代码
"theme": {
"@brand-primary":"red",
"color-text-base":"#333"
}

4.然后在项目根目录创建一个 config-overrides.js 用于修改默认配置,并添加以下内容
const {override,fixBabelImports,addLessLoader } =require('customize-cra');
const theme =require('./package').theme
module.exports =override(
fixBabelImports('import', {
libraryName:'antd-mobile',
style:true,
}),
addLessLoader({
modifyVars:theme
})
);

如有不对的地方请及时指正