CRA 配置其他库

编程入门 行业动态 更新时间:2024-10-17 07:25:52

<a href=https://www.elefans.com/category/jswz/34/1673785.html style=CRA 配置其他库"/>

CRA 配置其他库

文章目录

    • postcss-pxtorem
    • bee-mui
    • ant与antd-mobile

postcss-pxtorem

  • 注意: 引用postcss及其插件时,应将配置postcss的配置项置于less/sass等的配置项之后,以免引起错误(rewire的本质是覆写);
// 使用 postcss + postcss-pxtorem 进行 rem 转化
const configPost = (config) => {require('react-app-rewire-postcss')(config, {plugins: loader => [require('postcss-pxtorem')({rootValue: 108,unitPrecision: 5,propList: ['*'],exclude: /node_modules/i})]})
}

bee-mui

  • bee-mui是一个自己写的库,用它来完成一些css-reset及常用的一些css tools
  • 该库使用的是scss,请明白这一点
// npm i -S git+.git#branch

ant与antd-mobile

  • 作为一个优秀的前端UI框架,添加ant / antd-mobile往往能达到开箱即用的效果
  • cnpm i -S antd
  • cnpm i -S antd-mobile
import Button from 'antd-mobile/lib/button'
import 'antd-mobile/lib/button/style/index.css'
  • 这样的引入方式不太雅观且过于复杂,官方推荐使用babel-plugin-import来进行按需加载(需要修改babel-loader)
  • 通常情况下你使用了CRA框架,而且使用了react-app-rewire,此时,可使用custom-cra来对babel-loader进行修改
  • 这里推荐使用style:true,能大大减少代码体积,但是由于antd用的是less,所以这里要CRA支持less预载器
  • (此条存疑?) 推荐使用按需加载详情见 CRA-react-app-rewired使用
// cnpm i -D babel-plugin-import
// cnpm i -D customize-cra// 使用 custom-cra + babel-plugin-import 对 antd 产品进行按需加载
const configBabelPluginForAntd = (config) => {require('customize-cra').fixBabelImports('antd-mobile', {style: 'css'})(config)
}

更多推荐

CRA 配置其他库

本文发布于:2024-02-05 08:25:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1673783.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:CRA

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!