react 使用 styled-components-px2vw

9 篇文章 0 订阅
5 篇文章 0 订阅

在vue脚手架里面做styled-components-px2vw适配的时候在根目录创建postcss.config.js即可使用

在react里面使用@craco/craco

// craco.config.js
const params = {
  unitToConvert: 'px', // 需要转换的单位,默认为"px"
  viewportWidth: 1920, // 设计稿的视口宽度
  unitPrecision: 6, // 单位转换后保留的精度
  propList: ['*'], // 能转化为vw的属性列表
  transformRuntime: true // 设置 transformation:true 之后,可以转换被字符串模板嵌套的字符串表达式
}
module.exports = {
  // 这个babel是babel-plugin-styled-components-px2vw对styled-components做vw适配
  babel: {
    plugins: [
      ["styled-components-px2vw", params],
    ],
  },
  style: {
    postcss: {
      plugins: [require('postcss-px-to-viewport')(params)],
    },
  },
};

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值