react-create-app脚手架使用antd-mobile定制主题

按照官网的做法做了很久都没找到头绪,而且各种报错, 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

  })

);


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

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容